Skip to content

fix: default chart source to last statement execution with results - #1735

Merged
kgopal492 merged 2 commits into
pinterest:masterfrom
kgopal492:fix/chart-statement-default-no-data
Sep 16, 2026
Merged

kgopal492 merged 2 commits into
pinterest:masterfrom
kgopal492:fix/chart-statement-default-no-data

Conversation

@kgopal492

Copy link
Copy Markdown
Contributor

Summary

Problem (Why)

When editing a chart cell in a DataDoc whose query execution contains multiple statements, the chart composer (useChartSource) defaulted the selected statement to statementIdList[0] — the first statement. If that first statement produced no result rows (a non-result statement like SET/CREATE, or a SELECT returning 0 rows), the chart had no data to bind to and the chart config failed to load in the edit view.

Solution (What + How)

Default the selected statement to the last statement execution that is DONE with result_row_count > 0, rather than blindly picking the first statement. The statementExecutions memo (already computing exactly this filtered list) is moved above the default-selection effect and reused, and a statementExecution && guard is added to the filter to avoid dereferencing missing entries.

Test Plan

Manual verification in a local DataDoc:

  1. Run a query cell whose execution has a leading no-result statement and a trailing result statement, e.g.:
    SELECT 1 WHERE false;   -- statement 0: DONE, 0 rows
    SELECT 1 AS a, 2 AS b;  -- last statement: has rows
  2. Add a chart cell sourced from that execution and open the chart edit view.
  3. Before: chart config/data fails to load (defaults to the empty first statement). After: it defaults to the last statement with rows and loads correctly.

When editing a chart cell whose query execution has multiple statements,
the composer defaulted the selected statement to statementIdList[0]. If the
first statement produced no result rows (a non-result statement or a 0-row
result), the chart had no data to bind to and the chart config failed to
load. Default to the last DONE statement execution with result_row_count > 0
instead, and guard against missing statement executions in the filter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kgopal492
kgopal492 merged commit 3f26532 into pinterest:master Sep 16, 2026
3 checks passed
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.

2 participants