Commit Graph

9 Commits

Author SHA1 Message Date
Hugh A Miles II
25658110ba fix(dashboard): match chart semantics in raw mode, ordering, percent metrics
Further review of the form-data query-context rebuild:

- Raw-mode tables: ignore stale metrics/groupby (their controls aren't
  reset when hidden) and use only the selected columns, mirroring the
  frontend's getQueryMode (explicit query_mode, else all_columns).
- Ordering: default order_desc to False (ascending) for Table sort
  metrics and True for Pie, matching the plugins — so a row limit keeps
  the chart's top/bottom-N instead of flipping it.
- percent_metrics: skip the chart (re-save) rather than silently omitting
  the "% of total" columns the user sees, alongside the other
  unsupported-processing markers.

Adds regression tests for each; extracts a helper to keep the builder
under the complexity limit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-29 11:15:57 -04:00
Hugh A Miles II
808ba6f4b4 fix(dashboard): guard rebuild against post-processing and clause mismatch
Address further review of the form-data query-context rebuild:

- Skip the rebuild when the form data relies on processing the single
  query can't reproduce: time_compare, rolling_type, resample_rule, or
  aggregation=raw. Even allowlisted viz types would otherwise export
  values that differ from the chart.
- Big Number trendline: set granularity (so time_grain_sqla buckets the
  promoted time column) even with no active time_range.
- Export applies only WHERE-clause SIMPLE filters (via a new where_only
  arg), matching the chart, while the shared helper still converts all
  SIMPLE filters for the MCP path.

Adds regression tests for each case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-28 13:04:34 -04:00
Hugh A Miles II
719649fe1a fix(dashboard): make form-data query-context rebuild faithful
Address EnxDev review — the generic rebuild silently dropped several
query aspects, so allowlisted charts could export a different dataset
than they show:

- Ordering: derive `orderby` from order_by_cols (raw) or the sort metric
  / first-metric-descending (aggregate), so a `row_limit` returns the
  chart's top-N instead of an arbitrary N.
- Time range: set `granularity` (from granularity/granularity_sqla) so
  `time_range` is actually applied — but only when there is an active
  range, so a numeric column saved as granularity_sqla with no range
  isn't forced through date bucketing (verified against a real export).
- Custom SQL filters: map `SQL` adhoc filters + legacy top-level `where`
  into `extras.where`/`extras.having` by clause instead of dropping them.
- Table specifics: carry `percent_metrics` into metrics and pass
  `time_grain_sqla` through `extras`.
- Big Number: only promote granularity_sqla to a grouping column for the
  trendline viz (`big_number`), never `big_number_total`.

Also point the MCP chart compile/preview helpers
(adhoc_filters_to_query_filters, _build_query_columns) at this shared
module so they stop diverging (preview_utils still had the pre-fix
`columns` bug), and address nits: drop the `-O`-stripped assert by
restructuring the loop, parse the saved query_context once, and correct
the shallow-copy comment.

Adds unit tests for every derived field plus an export test asserting the
full query body reaches ChartDataQueryContextSchema().load.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 13:03:21 -04:00
Hugh A Miles II
de7dfc1585 fix(dashboard): harden form-data query-context rebuild edge cases
Address review of the empty query-context rebuild:

- columns_from_form_data no longer lets a stale, explicitly-present-but-
  empty `columns: []` key shadow the group-by dimensions (which silently
  dropped grouping and changed the aggregation). Prefer raw columns only
  when non-empty, else fall back to groupby.
- build_query_context_from_form_data now also honors legacy simple
  `filters` (already in QueryObject {col, op, val} shape) in addition to
  `adhoc_filters`, so legacy charts export the same filtered data they
  show; malformed entries are dropped.
- _rebuild_viz_types checks the config for None explicitly instead of
  using `or`, so an operator can disable the rebuild with an empty set
  instead of it silently falling back to the default allowlist.

Adds unit tests for each case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 13:06:29 -04:00
Hugh A Miles II
a1212ec089 test(dashboard): cover query-context rebuild edge cases
Add unit tests for the previously-uncovered branches of the empty
query-context handling: x_axis-as-adhoc-dict and the granularity_sqla
column fallback in the form-data builder (now 100%), and the eligible-viz
skip paths in _resolve_query_context when the saved form data is
unparseable, non-object, or has no datasource. All new source lines are
now exercised.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 10:01:28 -04:00
Hugh A Miles II
2bbada837b style: apply ruff-format to empty-query-context tests
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 16:14:59 -04:00
Hugh A Miles II
de29e984ff feat(dashboard): rebuild missing query context from form data in Excel export
Charts persist a query_context only once (re-)saved in Explore, so older
charts have params (form data) but no context and were skipped entirely
by the data export. When the saved context is empty, synthesize one from
the chart's form data (columns, metrics, adhoc filters, time range) and
run that instead.

The rebuild is a generic single-query mapping — it does not reproduce
plugin post-processing (pivot, rolling, forecast) or multi-query charts —
so it is gated to a conservative viz-type allowlist
(EXCEL_EXPORT_REBUILD_VIZ_TYPES: table, big_number_total, big_number,
pie). Charts of any other type without a saved context are still skipped
and listed for re-save, so no chart exports silently wrong or incomplete
data.

The form-data -> query-context logic lives in a new shared module
(superset.common.form_data_query_context), mirroring the approach the MCP
chart compile/preview path already uses. Adds unit tests for the builder
and export integration tests for the eligible-rebuild and
ineligible-skip paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 14:57:19 -04:00
Hugh A Miles II
c7a6c6fc9c fix(dashboard): skip charts with empty query context cleanly in Excel export
The export guard only skipped charts whose query_context was missing
(None/blank). A present-but-unusable context slipped through and failed
mid-export: "null" parsed to None and raised TypeError on item
assignment, while "{}"/{"queries": []} failed schema validation — all
landing in the generic error bucket with a noisy traceback instead of
the "no query context" remediation ("re-save in Explore"), which is the
correct guidance for every one of these cases.

Replace the shallow truthiness check with `_has_empty_query_context`,
which also treats an unparseable, non-object, or query-less context as
empty, and route all of them to ERROR_NO_QUERY_CONTEXT. Add a
parametrized test over blank/null/{}/empty-queries/malformed inputs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 12:38:33 -04:00
Hugh A. Miles II
00cb3037e7 feat(dashboard): export dashboard chart data to Excel (async, S3 + email) (#41133) 2026-07-21 12:17:00 -04:00