Skip to content

fix(server): validate decoded specs at /view, /h and /share - #114

Merged
jvdd merged 6 commits into
mainfrom
fix/validate-decoded-specs
Sep 28, 2026
Merged

jvdd merged 6 commits into
mainfrom
fix/validate-decoded-specs

Conversation

@jvdd

@jvdd jvdd commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #99.

Change

  • /view, /h/{n} and /share validate a decoded spec where it enters the server (_validated_dashboard in server.py): they build every trace with build_trace_from_spec. An invalid spec returns 400 Invalid spec: ....
  • The figure checks (one bar_mode, at most one heatmap) are a model validator on FigureSpec (spec.py). The builder, a decoded spec and every /dashboard/update request run them, so the server needs no import from figure.py. _validate_bar_modes and _validate_heatmap_count in figure.py are deleted.
  • The figure check reads bar_mode only from display. No producer has written params.bar_mode since the first release.
  • /view and /h/{n} render the specs that the rebuilt traces emit. So the page sees normalized values, for example the Plotly spelling of a lowercase color_scale from an older share URL. /share validates and encodes the spec as sent.
  • The Plotly adapter only reads the heatmap display values. _plotly_heatmap_color_scale, _plotly_heatmap_color_range, _check_plotly_heatmap_color_norm and _HEATMAP_STYLE_INVARIANT_ERROR are deleted, with the adapter's import from the trace helpers. The ECharts adapter keeps its checks.
  • CorrHeatmap.from_trace_spec rejects a color_norm key, because the adapter check that rejected it is gone.
  • Architecture.md: the heatmap styling contract and the request flow.

Impact

  • A hand-edited or imported spec with an invalid color_range or color_norm gave HTTP 500 at /view, and /share returned a URL that failed later. Both now return 400 with the message of the trace.
  • A decoded spec with two heatmaps in one figure (Allow at most one heatmap trace per figure #101) or mixed bar_modes now returns 400 at /view and /share, and 422 at /dashboard/update. Before, /dashboard/update accepted it.
  • An older share URL with "viridis" renders viridis.
  • A hand-made TraceSpec without required params (for example n_points) now gets 400 at /view. Before, the page rendered and its first /dashboard/update failed with 500.
  • Not changed: /dashboard/update still returns 500 for an invalid trace, because build_trace_from_spec runs outside a try there.

Tests

  • TestDecodedSpecValidation (tests/test_integration.py): an invalid color_range ("nope", [5, 1]), color_norm="sqrt", a log range from 0 on histogram2d and on geo_histogram2d, and a corr_heatmap with color_norm, each at /view and /share. Also two heatmaps at both routes and at /dashboard/update, and an old "viridis" spec rendering "Viridis". All 9 fail on the parent branch.
  • TestTraceSpecRoundTrip (tests/test_spec.py): rebuilding each trace from its builder spec gives the same TraceSpec, for every registered trace type.
  • On this branch merged with main: pytest tests: 2289 passed, 1 skipped. pytest -m browser tests: 317 passed, 12 skipped.

@codspeed

codspeed Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing fix/validate-decoded-specs (f5d523d) with main (8f9f588)

Open in CodSpeed

Base automatically changed from refactor/one-heatmap-per-figure to main September 28, 2026 09:44
@jvdd
jvdd merged commit ea7939b into main Sep 28, 2026
18 checks passed
@jvdd
jvdd deleted the fix/validate-decoded-specs branch September 28, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decoded specs skip trace validation: invalid display values give HTTP 500 at /view, and /share accepts them

1 participant