Skip to content

Feat: accept kebab-case field names in a reporter's input - #2948

Open
BelhsanHmida wants to merge 35 commits into
mainfrom
feat/reporter-input-kebab-case
Open

BelhsanHmida wants to merge 35 commits into
mainfrom
feat/reporter-input-kebab-case

Conversation

@BelhsanHmida

@BelhsanHmida BelhsanHmida commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

A reporter's input only took snake_case field names (source_types, most_recent_beliefs_only), while the flex-config and the report parameters around it use kebab-case, and "source-types" was refused as an unknown field.

This PR makes kebab-case the documented spelling of a reporter's input, and keeps snake_case working for existing reports and automations. For example:

input:
  - sensor: 3
    source-types: [forecaster]          # documented spelling
  - sensor: 4
    exclude_source_types: [reporter]    # still accepted

An input giving a field in both spellings is refused:

{'input': {1: {'exclude-source-types': ["Given as both 'exclude-source-types' and 'exclude_source_types'. Use only 'exclude-source-types'."]}}}
  • Each multiword field of the Input schema gets a kebab-case data_key: event-starts-after, event-ends-before, belief-time, beliefs-after, horizons-at-least, horizons-at-most, user-source-ids, source-account-ids, source-types, exclude-source-types, most-recent-beliefs-only, most-recent-events-only, most-recent-only, use-latest-version-per-event, one-deterministic-belief-per-event, one-deterministic-belief-per-event-per-source and sum-multiple.
    The Python names stay as they are, so the reporters themselves are unchanged, and so is a Python caller passing deserialized input, such as compute(input=[dict(source_types=["forecaster"])]).
  • The snake_case spelling is accepted through SupportsLegacyFieldAliases, with the aliases derived from the declared fields, so a field added later cannot miss its legacy spelling.
  • SupportsLegacyFieldAliases gets an opt-in refuse_both_spellings flag. Without it, the canonical spelling wins and the other is left behind, which a schema refusing unknown fields reports as a bare "Unknown field". The API schemas using the mixin keep their behaviour.
  • Data sources do not change: a reporter's source is identified by its config, and the input is part of the parameters, which a reporter does not save unless asked to (see below).
  • flexmeasures jobs check-source-references also finds a source named under user-source-ids, which is how report jobs now carry it.
  • Copying an automation into another organisation also checks the data sources and organisations a report's input names in its snake_case spelling, as every existing report automation stores them.
  • A data generator saving its parameters (save_parameters=True) still leaves each input's window (event-starts-after, event-ends-before, belief-time) off its data source, now that the input dumps it in kebab-case.
  • The regularise report template and the docs (reporting, data pipelining, the toy reporter tutorial and its script) use kebab-case. The reporting docs listed an account_id filter, which does not exist; it is now source-account-ids.
  • Added changelog item in documentation/changelog.rst

For hosts and plugin developers

  • Report jobs now carry their input in kebab-case, which a v1.1 worker refuses as unknown fields. Restart the workers together with the web processes when upgrading, rather than one after the other.
  • A reporter saving its parameters (save_parameters=True, which no built-in reporter does) stores a multiword input field in kebab-case from now on. Its data source is identified by those stored parameters, so its first run after the upgrade records under a new data source.

Names to confirm

Two fields were spelled mechanically, where a name used elsewhere could replace them. Please confirm or pick the other:

  • belief_time became belief-time. The report parameters and data requests call the same cut-off prior, so prior would read the same everywhere, but it also renames the field rather than only respelling it.
  • source_account_ids became source-account-ids. Sensor references and data requests call this filter source-account, which would give the filter one name everywhere (see the table in the data pipelining docs).

Look & Feel

flexmeasures add automation --type reporting --parameters report.yaml, where report.yaml gives one input both spellings:

Invalid report automation: {'parameters': {'input': {0: {'source-types': ["Given as both 'source-types' and 'source_types'. Use only 'source-types'."]}}}}
Aborted!

The same report in kebab-case and in snake_case records the same values under the same data source, through flexmeasures add report and through a report automation, for the PandasReporter and the AggregatorReporter.

How to test

pytest flexmeasures/data/schemas/tests/test_reporting.py flexmeasures/data/schemas/tests/test_utils.py flexmeasures/data/schemas/tests/test_field_naming.py flexmeasures/data/tests/test_data_source.py flexmeasures/api/v3_0/tests/test_asset_copy_automations_fresh_db.py

Or by hand: run flexmeasures add report --reporter PandasReporter with an input using source-types: [forecaster], then with source_types: [forecaster] on another output sensor, and compare the two sensors' data and sources. Then give one input both spellings and see it refused.

Further Improvements

Related Items

Closes #2946.
Follow-up to #2804, from its review. Part of #2540.


Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

An output-source-type in the reporter config (e.g. forecaster, for a sum of forecasts) replaces the class default 'reporter'.
The field has no default, so configs that leave it out dump unchanged and existing sources keep their attributes hash.
MemberFilterSchema now derives from Schema, as a member filter is no reporter config.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…r, too

A reporter configured to save under a forecaster-type source left that source unable to set its reporter up again,
because only the registry named by the source's type was looked in.
A data generator found that way is only accepted if its config says to save under the source's type.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
The aggregator looked for its partial aggregates, and the sensor status for the members they left out, among reporter-type sources only.
A report saved under another type (see output-source-type) would leave a stale partial aggregate as the latest belief, and drop the missing-members warning.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
The sources API gets a generator_type filter, matching sources by model against the registered data generators of that kind.
The automation source picker uses it instead of the source type, so a report automation can pick an aggregator saving under a forecaster-type source,
and a forecast automation no longer lists such a source, which it would refuse.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Includes when not to set output-source-type, and that a forecast whose "auto" entry filters sources does not leave out forecasters by default.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…nerator that does not exist

Field names reach the wire with dashes.
A typo such as generator-type=reportr now gets a 422, rather than an empty list that reads as if no source matched.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…urce types

Judging every source type for missing members, rather than reporters only, had the status look the sensor's sources up again for each type.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Covers the source and its hash when the field is left out, the label, refusing an unknown type,
leaving the aggregated forecast out of the training data of a forecast, setting the reporter up again from its source,
report automations (API and plugin handler), partial aggregates and their status, and the generator-type filter.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…s missing members

The status looked the sensor's sources up for the stalenesses, and again for the missing members.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…other type

The check ran only for a data generator found among the other kinds,
so a reporter-type source with a config naming the forecaster type set its reporter up, which then went on recording reports under it.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
A source of another type, such as a demo script, can carry a model named after a data generator,
but it stores no data generator to set up.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
The output-source-type of a reporter config and the generator-type filter of the sources API share one validator.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…r anyway

A config saying 'reporter' now has the source of the same config without it,
rather than a source of its own that would split the sensor's reports, and leave partial aggregates of the old source unsuperseded.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…ad of an output-source-type config field

A sum that includes a forecast is a forecast, so the AggregatorReporter now saves each event under a forecaster-type source if any belief that went into it came from a forecaster, under a scheduler-type source if any came from a scheduler, and under a reporter-type source otherwise.
Nobody has to remember a setting, and the field had no use left but mislabelling, so it is dropped before it is released.
Partial aggregates follow the same rule, and a complete aggregate supersedes a partial one of any type this report saves under.
A reporter is still set up again from a forecaster-type source, and refused on forecast paths.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…tor-type

`data-generator` takes the class name that automations and the source details already use, matched case-insensitively and including subclasses, so `data-generator=Reporter` lists every report and `data-generator=AggregatorReporter` only the sums, whatever their type.
The automation source picker uses it, and its placeholder no longer says "class".

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
… reporter from it

The command crashed with an AttributeError on None instead.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Also explain source type versus data generator with the new filter, and how to recompute sums saved as reports before this change.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…e takes it

A forecaster-type sum of forecasts stores a reporter, so a forecast automation refuses it;
the refusal now says so in the user's terms, and to set the automation type to reporting.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
A name that is neither an installed data generator nor the model of a source the user can list,
such as a typo, now gets a 422 rather than an empty list.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
A report from the aggregator can be saved under a sibling source of another type,
so the tooltip no longer says that results always go under the picked source.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
…picker

Such a source is of type forecaster but stores a reporter, so a forecast automation cannot use it;
rather than leaving it out, the picker lists it greyed out, saying why and which automation type takes it.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
SupportsLegacyFieldAliases lets the canonical spelling win, which leaves a schema that refuses unknown fields with a vague "Unknown field" for the legacy one.
The opt-in refuse_both_spellings flag names both spellings instead.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Each multiword field of a reporter's input, such as source-types, is now spelled in kebab-case, like the flex-config and the report parameters.
The snake_case spelling is still accepted, so existing reports and automations keep working, but a field given in both spellings is refused, naming both.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
A reporter's input can now name its user sources as user-source-ids, and report jobs carry it that way, so the check for waiting jobs that refer to a data source looks under both spellings.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
A data generator saving its parameters drops each input's window, which changes from run to run.
A reporter's input now dumps that window in kebab-case, which was kept, so each run would have made a new data source.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
A copy into another organisation checks the data sources and organisations an automation names.
It looked only under each field's current spelling, so a report automation stored with user_source_ids or source_account_ids skipped that check.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Also name source-account-ids in the reporting docs, where they listed an account_id filter that does not exist.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@BelhsanHmida BelhsanHmida added this to the 1.2.0 milestone Dec 1, 2026
@BelhsanHmida BelhsanHmida self-assigned this Dec 1, 2026
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
@read-the-docs-community

read-the-docs-community Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

@Flix6x Flix6x left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Mohamed! I went through #2804's new commits and this PR together, at both heads, on a test database. I ran flexmeasures add report with the AggregatorReporter and the PandasReporter, and a report automation run by a worker, each with the input in snake_case and in kebab-case.

#2804 (all eight points of my last review)

All done, mostly in my own wording: main merged, the API entry under v3.0-38 (right, since v3.0-37 shipped on November 29), the forecast automation's 422 and the greyed-out summed forecast in the picker that says why, the 422 for an unknown data-generator, the tooltip and the docs sentence. Thanks for filing #2946 and #2947 too. I'll approve #2804 separately.

What I checked here

  • Kebab-case input is refused at #2804's head and accepted here. Kebab-case and snake_case give the same events, the same totals and the same data source, for both reporters, also with several kebab-case fields at once.
  • An input giving a field in both spellings is refused, naming both.
  • A report automation with kebab-case input is created, stores the input as given, queues a job in kebab-case, and the worker computes the same report under the same source.
  • jobs check-source-references, save_parameters and copying an automation handle both spellings. The upgrade note on restarting workers together with the web processes is clear.
  • The new tests, the reporter tests, the report CLI and API tests and the automation tests pass here, and so does CI.

Requested changes

  1. Names: please use prior and source-account instead of belief-time and source-account-ids, as you suggested. The report's own parameters and the data requests already call this cut-off prior. Sensor references and data requests call the account filter source-account, as the table in data-pipelining.rst shows. Each filter then has one name everywhere. The snake_case aliases simply map belief_time to prior and source_account_ids to source-account (and DataGenerator's list of window fields to leave off a source would need prior).
  2. Snake_case only for the fields that had it. Input.legacy_field_aliases is derived from all declared multiword fields, so every field added later gets a snake_case spelling it never had (and the field-naming test requires that). New fields should be kebab-case only. Please write the alias dict out, listing the multiword fields as of v1.1 (with belief_time → prior and source_account_ids → source-account after the rename), and adjust the test accordingly.

Fixed by us on this branch

  • flexmeasures add forecasts --source <id> crashed on a summed forecast's source, with AttributeError: 'NoneType' object has no attribute 'set_job_trigger': the command didn't check whether get_data_generator returned a forecaster. This predates #2804, but #2804 makes forecaster-type sources that store a reporter common, and its docs now say the forecasting CLI doesn't accept them. I'm pushing a fix to this branch right after this review: the command will abort with the same message as the automation's 422 (_source_refusal), as add report --source does, with a test.

Follow-up issue (not this PR)

Could you open one under #2540 for the multiword fields of a report outside input? These are check_output_resolution, belief_horizon and the PandasReporter's use_latest_version_only in the parameters, and required_input, required_output, df_input, df_output and skip_if_empty in the PandasReporter's config. Today a report written in kebab-case still mixes spellings. The issue could also cover this: an AggregatorReporter input with horizons_at_most (or another search criterion the aggregator sets itself, such as the event window) crashes with TypeError: ... got multiple values for keyword argument, in either spelling. It should be refused with a clear message instead.

A forecaster-type source may store a reporter, such as the AggregatorReporter
that saves a sum of forecasts, so get_data_generator returns None for it and
the command crashed with an AttributeError. Abort instead, in the words a
forecast automation refuses such a source with (_source_refusal), as
`add report --source` already refuses a source it cannot set up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@Flix6x

Flix6x commented Dec 2, 2026

Copy link
Copy Markdown
Member

Follow-ups of my review:

  • Pushed f0b0767: flexmeasures add forecasts --source now refuses a source that stores no forecaster (such as a sum of forecasts), in the words a forecast automation's 422 uses (_source_refusal), rather than crashing with an AttributeError. It comes with a CLI test that fails without the fix, and a changelog entry. The touched CLI tests pass (test_data_add_db.py, test_data_add_fresh_db.py, test_automations.py).
  • Not done yet: approving Feat: reporter output source type #2804 and squash-merging it (CI is green, head unchanged at d63d1bed2). That still needs my own go-ahead outside the review session, so Feat: reporter output source type #2804 stays blocked by my earlier "changes requested" for now.

@Flix6x Flix6x mentioned this pull request Dec 3, 2026
13 tasks done
Base automatically changed from feat/reporter-output-source-type to main December 3, 2026 08:54

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants