Skip to content

Handle standardized sensors_to_show plots in flexmeasures show asset#2189

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-asset-show-crash
Open

Handle standardized sensors_to_show plots in flexmeasures show asset#2189
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-asset-show-crash

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

flexmeasures show asset --id <asset_id> crashed with KeyError: 'sensors' when sensors_to_show used the standardized schema (title + plots). The CLI deserialized to the new structure but still rendered the legacy top-level graph["sensors"] shape.

  • CLI output path now supports standardized schema

    • Replaced legacy rendering in show_generic_asset with _format_sensors_to_show(...).
    • Formatting now iterates graph["plots"] and renders supported plot variants:
      • {"sensor": ...}
      • {"sensors": [...]}
      • {"asset": ..., "flex-model": ...}
      • {"asset": ..., "flex-context": ...}
  • Resilient fallback behavior

    • Unexpected graph/plot shapes no longer crash rendering.
    • Unknown plot payloads are stringified for visibility instead of raising.
  • Regression coverage for CLI rendering

    • Added coverage for standardized plots-based sensors_to_show output.
    • Added direct formatter coverage for asset/flex-* plot references and unknown plot dictionaries.
def _format_sensor_plot(plot: dict) -> str:
    if "sensor" in plot:
        return str(plot["sensor"])
    if "sensors" in plot:
        return str(plot["sensors"])
    if "asset" in plot:
        asset_text = f"asset={plot['asset']}"
        reference_keys = [
            f"{key}={plot[key]}"
            for key in ("flex-model", "flex-context")
            if key in plot
        ]
        return f"{asset_text} ({', '.join(reference_keys)})" if reference_keys else asset_text
    return str(plot)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • publicsuffix.org
    • Triggering command: /home/REDACTED/work/flexmeasures/flexmeasures/.venv/bin/pytest pytest (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix crash in flexmeasures show asset for valid sensors configuration Handle standardized sensors_to_show plots in flexmeasures show asset May 20, 2026
Copilot AI requested a review from BelhsanHmida May 20, 2026 11:00
@BelhsanHmida BelhsanHmida added bug Something isn't working CLI labels May 21, 2026
BelhsanHmida and others added 2 commits May 21, 2026 18:07
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Signed-off-by: Mohamed Belhsan Hmida <149331360+BelhsanHmida@users.noreply.github.com>
@BelhsanHmida BelhsanHmida marked this pull request as ready for review May 21, 2026 17:08
Copy link
Copy Markdown
Contributor

@BelhsanHmida BelhsanHmida left a comment

Choose a reason for hiding this comment

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

Approved, fixes the issue.

@BelhsanHmida BelhsanHmida requested a review from Flix6x May 21, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flexmeasures show asset crashes for assets with standardized sensors_to_show plots

2 participants