Repository navigation
Conversation
sensors_to_show becomes nullable: NULL means no graphs were chosen, so graphs are suggested, and [] means no graphs. A migration turns every stored [] into NULL (until now, [] meant "suggest"), and the downgrade turns NULL back into []. validate_sensors_to_show suggests only when sensors_to_show is None, and returns the suggestions in the plots form, which the Vega-Lite builder draws (it skipped the old top-level "sensors" form, so the chart showed no graphs while its data loaded the suggested sensors). suggested_sensors_to_show gives the same suggestions with sensor IDs, for the graph editor. `flexmeasures show asset` and the graph page's legend count no longer fail on NULL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
… suggested graphs
POST and PATCH /api/v3_0/assets accepted [] but refused null ("may not be null").
Now null resets sensors_to_show, so graphs are suggested, while [] still means no graphs.
The audit log says which of the two was set, and the field is described in the OpenAPI spec.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <claessen@seita.nl>
…sensors_to_show When sensors_to_show is not set, the Edit Graphs dialogue starts from the graphs the page suggests, under a note that marks them as suggested, rather than from no graphs. Save stores them only once the user edits them, and removing every graph and saving stores [], which shows no graphs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
… and [] none Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
|
📖 6 files modified
Preview · build overview · flexmeasures · built Dec. 5, 2026, 11:06 a.m. UTC |
Without none_as_null, setting sensors_to_show to None (PATCH or POST with null, or copying an asset whose graphs are suggested) stored the JSON value null, which the migration's IS NULL misses: the downgrade left those assets with null rather than []. The migration now also handles a JSON null both ways. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
Flix6x
commented
Dec 5, 2026
Flix6x
left a comment
Member
Author
There was a problem hiding this comment.
Self-review, at head 59466bc (on today's main).
What holds
- An asset whose graphs were never chosen draws its suggested graphs again: one graph for two sensors sharing a unit, a graph each otherwise. On
mainits chart has no rows, while the chart data still loads both sensors. []now means no graphs, and its chart data loads nothing. A new asset, made in code or byPOSTwithoutsensors_to_show, starts unset.- Edit Graphs starts from the suggested graphs only when nothing was chosen, and every edit (titles, y-axis, plots) makes them the user's own to save.
- The new tests guard the fix: the 8 cases in
test_suggested_sensors_to_show.pyfail onmain. The asset API, UI andflexmeasures showtests pass.
Fixed in this PR since (pushed after this review)
nullwas stored as the JSON valuenull, not as SQL NULL. The column'sJSONBtype storesNoneas JSONnullunlessnone_as_null=True. Only a column left unset at insert was SQL NULL. SoPATCH/POSTwithnull, and copying an asset whose graphs are suggested, stored JSONnull. The app reads both asNone, but the downgrade'sWHERE sensors_to_show IS NULLmissed these assets. They keptnullunderNOT NULL, andflexmeasures show assetthen failed on them in the downgraded version. The column now usesJSONB(none_as_null=True). The migration also turns a JSONnullinto SQL NULL on upgrade, and into[]on downgrade. The API test now checks the stored SQL NULL, and the migration test has a JSON-nullrow. A new test checks that every nullable JSON/JSONB column in FlexMeasures usesnone_as_null=True, so a future column can't repeat this.sensors_to_showis the only one today.- No way back to suggested graphs in the UI. Once graphs were saved, going back to suggested graphs took a
PATCHwithnull. The Edit Graphs dialogue now has a subtle Use suggested graphs option for that, shown only when graphs were chosen.
Worth knowing
- #2943 also adds a migration on
d5b8f3a1c962, so whichever of the two merges second needs itsdown_revisionmoved. - Deleting the only sensor in an asset's graphs now leaves no graphs, rather than suggested ones, as the description says. No graphs were drawn in that case on
maineither.
A guard against the sensors_to_show bug coming back in another column: without none_as_null, None is stored as the JSON value null, which an IS NULL query misses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
Once graphs have been chosen for an asset, a small muted link under the graphs (after a confirm) sets sensors_to_show to null, so the asset shows suggested graphs again, without needing the API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
Member
Author
|
Follow-ups of the review, done:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An asset whose graphs were never chosen shows no graphs on its graph page, while the chart data still loads two of its sensors, and the Edit Graphs dialogue shows no graphs either.
GenericAsset.sensors_to_showwasnullable=False, default=[], so "never chosen" and "no graphs" were the same value.validate_sensors_to_showsuggests graphs whenevernot self.sensors_to_show, but_suggest_default_sensors_to_showreturned the old top-level form ({"title": None, "sensors": [...]}), whichchart_for_multiple_sensorsskips since feat: Adapting flex-config to SensorsToShowSchema #1904 (v0.32), as it only readsplots. The chart data (which flattens either form) still loads the two suggested sensors.asset_graph.html) reads the rawasset.sensors_to_show, so it starts empty.Confirmed on
main: an asset with two kW sensors and the default[]gets[{'title': None, 'sensors': [<Sensor 1>, <Sensor 2>]}]fromvalidate_sensors_to_show(), no rows in its Vega-Lite spec, and both sensors in its chart data.What changes
sensors_to_showis nullable, with NULL as the default: NULL means no graphs were chosen, so graphs are suggested, and[]means no graphs. A migration turns every stored[]into NULL (none of them was a deliberate choice, as[]meant "suggest" until now) and drops the'[]'server default; the downgrade turns NULL back into[].validate_sensors_to_showsuggests only whensensors_to_show is None, and returns the suggestions in the currentplotsform, so the Vega-Lite builder draws them: the first two sensors in one graph if they share a unit, or a graph each if not, as before. Withsuggest_default_sensors=False(the sensor status overview insensors.py), NULL gives no graphs. A newGenericAsset.suggested_sensors_to_show()gives the same suggestions with sensor IDs, in the stored form.sensors_to_showis NULL, with a note that marks them as suggested; Save refuses to store them unedited (a toast says there is nothing to save), and any edit makes them the user's own to save. Removing every graph and saving stores[], which shows no graphs. Once graphs have been chosen, a small muted "Use suggested graphs" link under them (after a confirm) stores NULL again and reloads, so the asset is back to suggested graphs without the API.POST/PATCH /api/v3_0/assetsacceptsensors_to_show: nullto reset to suggested graphs (it was refused as "may not be null"), and keep[]as no graphs; the field now has a description in the OpenAPI spec, and the audit log says "not set, so graphs are suggested" or "no graphs".flexmeasures show assetprints "Not set (graphs are suggested)" rather than failing on NULL, and the graph page's legend count no longer fails on NULL.views/asset-data.rst), the main changelog (bugfix, plus the migration in the upgrade warning) and the API changelog (nullaccepted; assets that had[]now return"null").Not changed: when deleting a sensor or asset prunes every graph from another asset's
sensors_to_show, or copying an asset drops them all, the result stays[], which now means no graphs (it used to mean suggested graphs).How to test
pytest flexmeasures/data/tests/test_suggested_sensors_to_show.py: NULL draws the suggested graphs (the Vega-Lite spec has one row with both sensors for a shared unit, a row each otherwise),[]draws none, and a new asset has NULL. These fail onmain.pytest flexmeasures/data/tests/test_sensors_to_show_nullable_migration.py: the upgrade turns[]into NULL and keeps chosen graphs, the downgrade turns NULL back into[]and restores NOT NULL with its default.pytest flexmeasures/api/v3_0/tests/test_assets_api.py -k no_graphs_and_back(PATCH[]andnull, stored as SQL NULL) andpytest flexmeasures/ui/tests/test_asset_crud.py -k graphs_page(the dialogue starts from the suggestions only for NULL, and offers "Use suggested graphs" only once graphs were chosen).pytest flexmeasures/data/tests/test_jsonb_columns.py: every nullable JSON column stores None as SQL NULL (none_as_null=True).flexmeasures db upgrade, then open the graph page of an asset with sensors and no chosen graphs: two suggested graphs show, and Edit Graphs lists them under a "Suggested graphs" note. Save without edits stores nothing; remove every graph and save, and the page shows no graphs; click "Use suggested graphs" under the graphs in Edit Graphs (orPATCHthe asset with{"sensors_to_show": null}) to get the suggestions back.🤖 Generated with Claude Code