Repository navigation
Feat: automation select data source - #2584
Conversation
…ne type Context: - The listing returned every data source the caller may read, with no way to search it or to ask for one kind. A picker offering a choice of forecasters therefore had to fetch them all and sift through them in the browser. Change: - Add a `filter` of space-separated search terms, matched against a source's name, its model and its id prefix, the way the sensors listing already searches, and a `type`, which narrows the listing to one source type. - Move the rule about which sources a user may read into the data-sources service, as `get_readable_source_account_ids` and `user_may_read_source`, so that it can be applied outside this endpoint without being restated. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…nder Context: - A data source stores a data generator and the configuration it runs under, and the results computed under it are recorded on it. `flexmeasures add automation` has taken `--source` since the command was written, so several automations can share one generator and one lineage of data, but the API could only be handed a class and a config, which reaches an existing source by accident, when what it builds happens to hash to the same attributes. Change: - Accept a `source` on the creation endpoint, deserialized to the DataSource the service already knows how to take. It cannot be combined with `data-generator` or `config`, which the source itself determines, and a schedule automation cannot name one, since it re-resolves its source from the asset and the flex config on every run and would move off the named one at the next run. - Require that the caller may read the source, by the same rule the sources listing applies. A source is otherwise a way to compute under, and record on, a generator configuration belonging to another organisation. The CLI runs without a user and stays trusted, as it already is for sensors. - Let DataSourceIdField dump None, so that the field's absent default serializes rather than failing the OpenAPI generation. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…tores Context: - The creation form asked for a data generator class and a config as free text, with no way to say "the one that automation already uses", and nothing showed what a generator would be configured with until after the automation existed. Change: - Add a search box above those two fields, which lists the data sources of the automation's own type, matched by id, by name and by generator class, and lists them on focus so they can be browsed without guessing a term. - Show the picked source's description and the configuration it stores, and disable the class and config fields while it is picked, since the source already determines both. Clearing it hands them back. - Drop the whole section for a schedule automation, which has no generator to name, and clear a selection when the type changes, as the source type does. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - #2554 rebuilt the same creation form this branch extends, and #2565 renamed flexmeasures/api/dev to flexmeasures/api/ui. Change: - Take main's creation form and re-apply the picker onto it: the picker joins the .chooses-generator fields rather than carrying its own wrapper, clearing a selection folds into main's type-change handler, and the submit path goes through main's readJsonField. - Assemble the POST payload before sending it, since a reused source replaces both the generator and the config, and follow test_asset_crud's payload assertions onto the new lines, adding one for the source branch. - Keep both sides' tests in test_automations_api, restoring the two parametrize decorators the merge separated from their functions. - Take v3.0-39 in the API change log, as main claimed v3.0-38. - Share test_automation_actions.automation_script in the picker's browser checks, which renders all five of the page's Jinja values rather than three. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Documentation build overview
46 files changed ·
|
… covers it The automations feature has not shipped yet, so the changelog describes where it ends up rather than the steps it took to get there. Someone reading the v1.1.0 notes never saw a version of the *New automation* form without a data source to pick, and a bullet announcing that one arrived tells them about a past they have no memory of. The per-PR list under *Automations, in detail* is the place where a contribution is still worth naming, so this PR's number joins the entry that already describes the creation form and the data source it records under. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…es it ``POST /assets/<id>/automations`` arrived at v3.0-37, inside this same unreleased cycle, so no API consumer has ever called it without a ``source``. The release will simply introduce the endpoint, with that field on it, and an entry saying it "now accepts" one describes a revision nobody integrated against. The ``GET /sources`` entry stays. That listing predates this cycle and is already in users' hands, so a new way to search and narrow it is a change they need told about. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…mplies The field's description had grown into a paragraph, restating what a data source stores, how the results are attributed to it, and why a schedule automation may not name one. All three are already in the automations documentation, where they have room to be explained, and none of them help someone reading the OpenAPI reference to decide what to put in the field. One sentence is left: it is the ID of a data source to reuse, in place of naming a generator and a config. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…aSourceIdField alone Giving the field a ``load_default`` of None put a default into the OpenAPI spec, which the generator then pushed back through the field's own serializer. A field that turns an ID into a DataSource has nothing to do with None, so it raised, and the way out taken at the time was to teach it to swallow None -- changing the field for every schema that uses it, to accommodate one field's setup. The field is simply not required, so say that instead. Nothing then asks for a default, the serializer goes back to doing one thing, and the published schema improves as well: ``source`` is now an integer that may be omitted, rather than a nullable integer defaulting to null. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
The API changelog entries of the two lines each keep a section of their own, and the page entry is main's, which now covers what both say. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
The creation form carried nine blocks of help text, several of them three to five lines, so the fields it was meant to explain were spread thin between paragraphs and the modal read as a page of prose with inputs in it. Each field's label now carries the info icon the sensor creation form already uses, with the same text behind it on hover. Two hints stay on the page, because they are the ones you act on while typing rather than read once: that the generator config can be left empty, and the offset example worth copying into the parameters. Bootstrap only turns those icons into tooltips when asked, so the page now initialises them, as the chart pages do. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Bootstrap appends a tooltip to the document body, where it sits at a z-index of 1080. The theme gives a modal 999993. A tooltip opened from a field inside the creation form was therefore built, shown and positioned correctly, and painted behind the modal, so hovering an info icon appeared to do nothing at all. Anchoring each tooltip to the modal that holds its icon puts the two in one stacking context, and the tooltip comes out on top. Icons outside a modal keep the body as their container. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…eps jobs The jobs column counts what the job cache returns, and that cache holds only the jobs Redis still has: FLEXMEASURES_JOB_TTL expires them, and the cache drops the ids it can no longer fetch. A daily automation two weeks old therefore shows a week of jobs on an instance that keeps them for a week, which reads as runs that never happened rather than as records that have been cleaned up. The column and the info panel now say so, naming the window this instance is configured for rather than pointing at the setting. The phrasing works for either shape the value takes, since a one-day retention reads as "a day" and not "1 day". The browser checks render the page's script through a bare Jinja environment, so that environment now carries the filter and the configuration value the page reads, keeping its promise that nothing is left unrendered. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
…pes unnarrowed A search from the automation form asked for every source a user may read, in whatever order Postgres returned them, so an instance with many sources sent its whole source table to the browser, and the sources shown could differ between two searches for the same term. The listing is now ordered with the most recently created source first, and takes a limit. The source types in the response are read from every source the user may read, rather than from the sources the call returns, so that narrowing the listing no longer narrows the types a client can offer to narrow it by. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
The search now asks for one source more than the list shows, which is what tells the list that there are more to narrow down to, and which keeps an instance with many sources from sending all of them to the browser on every pause in typing. The list therefore says that it leaves sources out rather than how many, which is no longer a number it has. A source picked and then left behind by closing the form used to still disable the data generator fields when the form was opened again, with nothing on screen to say why, so closing the form now clears the picked source. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
A client which fills in the whole creation form and leaves the source field empty sends a null source, which was refused with 'Field may not be null' rather than taken as the automation setting up its own data generator. Our own form works around this by leaving the field out altogether. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
…urces Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
|
I reviewed this and pushed the fixes I found, rather than handing back a list. Five commits, each on its own point:
The response's
Tests: three added (the limit and its ordering, the types surviving a filter, a null source accepted) plus two amended JavaScript checks, each confirmed to fail without the change it covers. One thing I did not change here:
One thing worth knowing: 🤖 Generated with Claude Code |
…nisation alone Almost every data generator's source belongs to no organisation, because nothing on the creation path passes one, and a source naming neither an organisation nor a user was readable by every authenticated user. The read check this pull request added therefore hardly ever refused anything. A source is now readable when it belongs to an organisation the user may read, when an automation they may read computes under it, or when it has recorded data on a sensor they may read, which is what makes it possible to ask what produced a number one is allowed to see. The first two are what makes a source one to work with: those are the sources the listing holds, because reusing a source means recording under its lineage, which is more than reading what it computed. The stored configuration follows the stricter rule as well, since a data generator's configuration names the sensors it runs on, which can be sensors of an organisation whose data the user cannot see at all. Two tests created sources belonging to no organisation to exercise version collapsing rather than visibility; their fixtures name an organisation now. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
…o work with Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
|
Following up on the thread about which data sources a user may read (#2625), I have implemented the three conditions discussed there, in the shape we settled on: a source is readable when any of them holds, while the listing and the stored configuration need the stricter two. The three conditions, and which question each one answers. They answer two different questions, and the stronger act deserves the stricter rule:
The two filters live in What changes in practice. Condition 1 is implemented as it was worded — coupled to an organisation you may read — so the previous blanket grant for a source naming neither an organisation nor a user is gone. That blanket was the reason the 403 on this PR hardly ever fired: every data generator's source is account-less today, because nothing on the creation path passes an organisation to
Tests. Three added, each verified red without its own fix: a source belonging to no organisation is neither listed nor readable; a source of another organisation that recorded on a sensor you may read is readable without its Docs: the access rules on both endpoints, the API change log, the automations feature page, and a changelog entry under Infrastructure / Support, since this narrows who may read a data source. 🤖 Generated with Claude Code |
…ad it The listing a source is picked from holds the sources the user may work with, while reading one source is allowed more widely, for a source which recorded data on a sensor they may read. Creating the automation checked the wider of the two, so a source that had recorded on one of the user's own sensors could be named for an automation of theirs, which records under that source and so writes into another organisation's lineage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
|
One more, found while re-reading my own change: creating the automation was checking the readable rule, not the usable one. That is the inconsistency the split exists to avoid. A source that had recorded data on one of your own sensors was readable, and the creation guard accepted it — so you could point an automation of yours at another organisation's source and record under its lineage, which is exactly what the listing refuses to offer you. A test pins it: a foreign source that has recorded on the user's own sensor reads back with a 200 and is refused for an automation with a 403, verified red under the old check. 🤖 Generated with Claude Code |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes data-source access-control semantics (previously public sources become non-readable) across the API, UI, and a shared service, which is security-sensitive and warrants final human review.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
This PR lets the API and UI reuse an existing data source when creating a forecast or report automation, bringing them in line with the CLI's long-standing --source option. Naming a source makes the automation reuse that source's data generator, configuration, and data lineage. It also generalizes the data-source read/reuse access rules into a shared service (data_sources.py) and extends GET /sources with filter/type/limit query parameters so the UI can offer a searchable source picker.
Changes:
- Add a
sourcefield toAutomationCreationSchema(mutually exclusive withdata-generator/config, refused for schedule automations), plus a service-side permission check that the caller may use the named source. - Centralize per-source access rules into
usable_source_filter/readable_source_filter(anduser_may_use_source/user_may_read_source), so a no-organisation source is no longer readable by everyone;attributesare only returned for usable sources. - Add a searchable/type-filtered/limited
GET /sources, and a UI source picker in the New automation form, with tests, docs, and changelog entries.
| File | Description |
|---|---|
flexmeasures/data/schemas/automations.py |
Adds source field and cross-field validation refusing it alongside generator/config or for schedules |
flexmeasures/data/services/data_sources.py |
New usable/readable source filters and user_may_* helpers |
flexmeasures/api/v3_0/sources.py |
New filter/type/limit params; access rules moved to the service; per-source read/attribute gating |
flexmeasures/data/services/automations.py |
Permission check that a named source is the user's to work with |
flexmeasures/api/v3_0/assets.py |
OpenAPI example of reusing a source |
flexmeasures/ui/templates/assets/asset_automations.html |
Source picker UI and submit logic; info-icon tooltips |
flexmeasures/ui/static/openapi-specs.json |
Regenerated spec for new params/field |
flexmeasures/ui/tests/..., flexmeasures/api/v3_0/tests/... |
Tests for the picker, access rules, and reuse behavior |
documentation/* |
Feature docs, main changelog, and API changelog entries |
I verified the schema validator reads the correct post-load attribute names, the models/columns referenced by the new SQL filters exist, the permission check runs before any DB mutation, the api_message pattern is consumed by the auth error handler, and the test fixtures/imports resolve. I found no functional bugs; the two comments are minor (a mid-phrase comment wrap that the repo's comment convention disallows, and a slightly inaccurate inline comment).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…omment Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl>
Flix6x
left a comment
There was a problem hiding this comment.
The picker and the permission model both look right to me now.
Since my earlier review: the source listing is ordered and bounded, its types survive the filters, the picker asks for no more than it shows and opens on a clean slate, an empty source is read as no source, and the API change log covers the new surface. The access rules are the three conditions from the thread above, split so that reading what a source computed is weaker than working with the source, with the stored configuration and the creation guard both on the stricter side.
Two things deliberately left for their own issues: #2630, where automations of plugin types still bypass the source check, and #2625, which gives data generators' sources an organisation and so makes the first condition select anything at all.
* api/v3_0/sources: search the data sources listing, and narrow it to one type Context: - The listing returned every data source the caller may read, with no way to search it or to ask for one kind. A picker offering a choice of forecasters therefore had to fetch them all and sift through them in the browser. Change: - Add a `filter` of space-separated search terms, matched against a source's name, its model and its id prefix, the way the sensors listing already searches, and a `type`, which narrows the listing to one source type. - Move the rule about which sources a user may read into the data-sources service, as `get_readable_source_account_ids` and `user_may_read_source`, so that it can be applied outside this endpoint without being restated. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * api/v3_0/assets: let an automation name the data source it computes under Context: - A data source stores a data generator and the configuration it runs under, and the results computed under it are recorded on it. `flexmeasures add automation` has taken `--source` since the command was written, so several automations can share one generator and one lineage of data, but the API could only be handed a class and a config, which reaches an existing source by accident, when what it builds happens to hash to the same attributes. Change: - Accept a `source` on the creation endpoint, deserialized to the DataSource the service already knows how to take. It cannot be combined with `data-generator` or `config`, which the source itself determines, and a schedule automation cannot name one, since it re-resolves its source from the asset and the flex config on every run and would move off the named one at the next run. - Require that the caller may read the source, by the same rule the sources listing applies. A source is otherwise a way to compute under, and record on, a generator configuration belonging to another organisation. The CLI runs without a user and stays trusted, as it already is for sensors. - Let DataSourceIdField dump None, so that the field's absent default serializes rather than failing the OpenAPI generation. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui/assets: pick a data source for a new automation, and see what it stores Context: - The creation form asked for a data generator class and a config as free text, with no way to say "the one that automation already uses", and nothing showed what a generator would be configured with until after the automation existed. Change: - Add a search box above those two fields, which lists the data sources of the automation's own type, matched by id, by name and by generator class, and lists them on focus so they can be browsed without guessing a term. - Show the picked source's description and the configuration it stores, and disable the class and config fields while it is picked, since the source already determines both. Clearing it hands them back. - Drop the whole section for a schedule automation, which has no generator to name, and clear a selection when the type changes, as the source type does. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui/assets: copy an automation into the creation form The Automations page could create an automation from scratch or edit one's recurrence, but a variation on an existing automation, such as the same forecast on a different schedule, had to be typed out again from its details. Each row's Actions menu now offers Copy, which opens the creation form with the original's type, recurrence, timezone and parameters filled in. Nothing is created until the form is submitted, so the copy is a starting point that can still be changed, rather than a command of its own. The copy is filled in inactive, so that a variation being worked on does not start running while it is still being edited, and so that two automations writing the same results never appear from a single click. Its name carries a (copy) suffix, cut to the 80 characters the field and the API allow, so that a long name loses its tail rather than the suffix that marks it. A forecast or report copy reuses the data source the original computes under, which already stores the data generator and its configuration, rather than naming that class and config again. A schedule automation resolves its source afresh on every run and cannot name one, so a copy of one names none. The parameters are carried over exactly as stored, which is safe here because the copy stays on the same asset, so the sensors they name stay valid and the creation endpoint checks them against the user's permissions as it would for any new automation. The creation form is now shared between New automation and Copy, so opening it blank clears what a copy left in it, rather than inheriting the last copy's settings. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * docs/changelog: point the data source picker entries at PR #2584 Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * docs/changelog: fold the copy button into the automations UI entry Automations have not shipped, so the changelog says what the feature is rather than how it got there: the entry that already covers creating and managing automations in the UI names Copy among the row's controls and carries this PR's number, instead of a bullet of its own. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * docs/changelog: carry this work on the automations entry that already covers it The automations feature has not shipped yet, so the changelog describes where it ends up rather than the steps it took to get there. Someone reading the v1.1.0 notes never saw a version of the *New automation* form without a data source to pick, and a bullet announcing that one arrived tells them about a past they have no memory of. The per-PR list under *Automations, in detail* is the place where a contribution is still worth naming, so this PR's number joins the entry that already describes the creation form and the data source it records under. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * docs/api: leave the automations endpoint to the release that introduces it ``POST /assets/<id>/automations`` arrived at v3.0-37, inside this same unreleased cycle, so no API consumer has ever called it without a ``source``. The release will simply introduce the endpoint, with that field on it, and an entry saying it "now accepts" one describes a revision nobody integrated against. The ``GET /sources`` entry stays. That listing predates this cycle and is already in users' hands, so a new way to search and narrow it is a change they need told about. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * data/schemas/automations: say what the source field is, not what it implies The field's description had grown into a paragraph, restating what a data source stores, how the results are attributed to it, and why a schedule automation may not name one. All three are already in the automations documentation, where they have room to be explained, and none of them help someone reading the OpenAPI reference to decide what to put in the field. One sentence is left: it is the ID of a data source to reuse, in place of naming a generator and a config. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * data/schemas: let the source field be plainly optional, and leave DataSourceIdField alone Giving the field a ``load_default`` of None put a default into the OpenAPI spec, which the generator then pushed back through the field's own serializer. A field that turns an ID into a DataSource has nothing to do with None, so it raised, and the way out taken at the time was to teach it to swallow None -- changing the field for every schema that uses it, to accommodate one field's setup. The field is simply not required, so say that instead. Nothing then asks for a default, the serializer goes back to doing one thing, and the published schema improves as well: ``source`` is now an integer that may be omitted, rather than a nullable integer defaulting to null. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui/assets: move the automation form's reference text onto info icons The creation form carried nine blocks of help text, several of them three to five lines, so the fields it was meant to explain were spread thin between paragraphs and the modal read as a page of prose with inputs in it. Each field's label now carries the info icon the sensor creation form already uses, with the same text behind it on hover. Two hints stay on the page, because they are the ones you act on while typing rather than read once: that the generator config can be left empty, and the offset example worth copying into the parameters. Bootstrap only turns those icons into tooltips when asked, so the page now initialises them, as the chart pages do. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui/assets: raise the form's tooltips above the modal they belong to Bootstrap appends a tooltip to the document body, where it sits at a z-index of 1080. The theme gives a modal 999993. A tooltip opened from a field inside the creation form was therefore built, shown and positioned correctly, and painted behind the modal, so hovering an info icon appeared to do nothing at all. Anchoring each tooltip to the modal that holds its icon puts the two in one stacking context, and the tooltip comes out on top. Icons outside a modal keep the body as their container. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * ui/assets: say that the job counts reach back only as far as Redis keeps jobs The jobs column counts what the job cache returns, and that cache holds only the jobs Redis still has: FLEXMEASURES_JOB_TTL expires them, and the cache drops the ids it can no longer fetch. A daily automation two weeks old therefore shows a week of jobs on an instance that keeps them for a week, which reads as runs that never happened rather than as records that have been cleaned up. The column and the info panel now say so, naming the window this instance is configured for rather than pointing at the setting. The phrasing works for either shape the value takes, since a one-day retention reads as "a day" and not "1 day". The browser checks render the page's script through a bare Jinja environment, so that environment now carries the filter and the configuration value the page reads, keeping its promise that nothing is left unrendered. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> * Order the data source listing, let a client limit it, and keep its types unnarrowed A search from the automation form asked for every source a user may read, in whatever order Postgres returned them, so an instance with many sources sent its whole source table to the browser, and the sources shown could differ between two searches for the same term. The listing is now ordered with the most recently created source first, and takes a limit. The source types in the response are read from every source the user may read, rather than from the sources the call returns, so that narrowing the listing no longer narrows the types a client can offer to narrow it by. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> * Bound the source search, and open the automation form on a clean slate The search now asks for one source more than the list shows, which is what tells the list that there are more to narrow down to, and which keeps an instance with many sources from sending all of them to the browser on every pause in typing. The list therefore says that it leaves sources out rather than how many, which is no longer a number it has. A source picked and then left behind by closing the form used to still disable the data generator fields when the form was opened again, with nothing on screen to say why, so closing the form now clears the picked source. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> * Read an empty source on an automation as no source at all A client which fills in the whole creation form and leaves the source field empty sends a null source, which was refused with 'Field may not be null' rather than taken as the automation setting up its own data generator. Our own form works around this by leaving the field out altogether. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> * Changelog: the source an automation reuses, and searching the data sources Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> * Drop a local import of ValidationError which the module already has Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> * Decide who may read a data source per source, rather than by its organisation alone Almost every data generator's source belongs to no organisation, because nothing on the creation path passes one, and a source naming neither an organisation nor a user was readable by every authenticated user. The read check this pull request added therefore hardly ever refused anything. A source is now readable when it belongs to an organisation the user may read, when an automation they may read computes under it, or when it has recorded data on a sensor they may read, which is what makes it possible to ask what produced a number one is allowed to see. The first two are what makes a source one to work with: those are the sources the listing holds, because reusing a source means recording under its lineage, which is more than reading what it computed. The stored configuration follows the stricter rule as well, since a data generator's configuration names the sensors it runs on, which can be sensors of an organisation whose data the user cannot see at all. Two tests created sources belonging to no organisation to exercise version collapsing rather than visibility; their fixtures name an organisation now. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> * Changelog and docs: which data sources are yours to read, and which to work with Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> * Naming a source for an automation takes more than being allowed to read it The listing a source is picked from holds the sources the user may work with, while reading one source is allowed more widely, for a source which recorded data on a sensor they may read. Creating the automation checked the wider of the two, so a source that had recorded on one of the user's own sensors could be named for an automation of theirs, which records under that source and so writes into another organisation's lineage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> * Address review: say which sources the types come from, and unwrap a comment Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> * Changelog: one entry for the automations page's actions, not two The merge of main brought in the entry PR #2563 had extended, beside this branch's own edit of the same line. Neither conflicted with the other, so both survived: the section carried the same 900-character bullet twice, differing only in whether it mentioned Copy and which pull requests it cited. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0129WrXeJ5gia2pctFH93BqC Signed-off-by: F.N. Claessen <claessen@seita.nl> --------- Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com> Signed-off-by: F.N. Claessen <claessen@seita.nl> Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com> Co-authored-by: F.N. Claessen <claessen@seita.nl> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>

Description
flexmeasures add automationhas taken--sourcesince the command was written, so several automations can share one data generator, one configuration and one lineage of data. The API could only be handed a class and a config, which reaches an existing source by accident — when what it builds happens to hash to the same attributes — and the UI had no way to say "the one that automation already uses".This PR gives the API and the UI the choice the CLI already had.
POST /assets/(id)/automationsaccepts asource: the id of an existing data source whose data generator and configuration the automation reuses, and under which it records what it computes. The service already tooksource=; only the request schema and the permission check are new.sourcecannot be combined withdata-generatororconfig, which a data source already determines (422).422). Its data source is re-resolved from the asset and the flex config on every run, so the next run would move it off the named source again. This mirrors the CLI, which already refuses--sourcewith--type scheduling.403), by the same ruleGET /sourcesapplies. Without it, a source is a way to compute under, and record on, a generator configuration belonging to another organisation. The CLI runs without a user and stays trusted, as it already is for sensors.GET /sourcesaccepts afilterof space-separated search terms — matched against a source's name, its model and its id prefix, the way the sensors listing already searches — and atype, which narrows the listing to one source type.get_readable_source_account_ids,user_may_read_source), so it is stated once and applied in both places.DataSourceIdFieldnow dumpsNone, so an optional source field's absent default serialises instead of failing the OpenAPI generation.documentation/features/automations.rst.documentation/changelog.rstBuilt on top of #2554, which rebuilt the same creation form: the picker joins its
.chooses-generatorfields rather than carrying its own wrapper, clearing a selection folds into its type-change handler, and the submit path goes through itsreadJsonField.Look & Feel
Creating a forecast automation that reuses data source 6:
The automation's
generator_idis 6, so its forecasts are recorded under that source, alongside the data it already holds.Naming both ways at once is refused:
{"message": {"source": ["data-generator cannot be combined with source: a data source already stores the data generator and the configuration it runs under."]}}In the UI, clicking into the empty box lists the forecasters; typing narrows them:
On an instance with many generators the list caps at 25 and says how many it leaves out, which is what makes searching by id or by model worth having.
How to test
New tests in
flexmeasures/api/v3_0/tests/test_automations_api.py:Run them with:
manual test: in automation page press new automation and test selecting a datasource
closes #2587
Sign-off