Skip to content

fix(chart): keep query-context updates bound to the chart's datasource#40955

Open
rusackas wants to merge 2 commits into
masterfrom
fix/chart-query-context-datasource-validation
Open

fix(chart): keep query-context updates bound to the chart's datasource#40955
rusackas wants to merge 2 commits into
masterfrom
fix/chart-query-context-datasource-validation

Conversation

@rusackas

Copy link
Copy Markdown
Member

SUMMARY

When a chart is updated with only a query_context (the
{query_context, query_context_generation} payload that report and alert
workers use to refresh a chart's cached payload), UpdateChartCommand
intentionally skips the ownership check so those background workers can save
context without owning the chart.

This change keeps that payload internally consistent: before saving, it
validates that the submitted query_context.datasource still references the
chart's own persisted datasource_id (and type). A payload that points at a
different datasource is rejected with a 400 rather than being stored as-is.
Payloads that don't carry a parseable datasource are unchanged — at execution
time they already fall back to the chart's own datasource — so there's no
behavior change for the normal save flow.

It's a small, well-scoped robustness check on the chart update path so a
chart's stored query context can't drift away from the chart's actual
datasource.

TESTING INSTRUCTIONS

Unit tests added in tests/unit_tests/commands/chart/update_test.py:

  • a query context targeting the chart's own datasource is accepted
  • a query context referencing a different datasource id/type is rejected
    (ChartInvalidError → 400), including the id-as-string case
  • payloads with no datasource / null datasource / unparseable JSON are left
    alone (no false positives)
pytest tests/unit_tests/commands/chart/update_test.py

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

@bito-code-review

bito-code-review Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #e31e08

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: d544bff..d544bff
    • superset/commands/chart/exceptions.py
    • superset/commands/chart/update.py
    • tests/unit_tests/commands/chart/update_test.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added the change:backend Requires changing the backend label Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 15.38462% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.27%. Comparing base (b05fe48) to head (c8b9e99).

Files with missing lines Patch % Lines
superset/commands/chart/update.py 8.69% 21 Missing ⚠️
superset/commands/chart/exceptions.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40955      +/-   ##
==========================================
- Coverage   64.28%   64.27%   -0.02%     
==========================================
  Files        2659     2659              
  Lines      144304   144330      +26     
  Branches    33260    33264       +4     
==========================================
- Hits        92773    92772       -1     
- Misses      49902    49927      +25     
- Partials     1629     1631       +2     
Flag Coverage Δ
hive 39.42% <15.38%> (-0.01%) ⬇️
mysql 58.15% <15.38%> (-0.02%) ⬇️
postgres 58.22% <15.38%> (-0.03%) ⬇️
presto 41.01% <15.38%> (-0.01%) ⬇️
python 59.68% <15.38%> (-0.03%) ⬇️
sqlite 57.84% <15.38%> (-0.02%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

On the query-context-only update path UpdateChartCommand intentionally
skips the ownership check so report and alert workers can refresh a
chart's cached payload. Validate that the submitted query context still
targets the chart's own datasource (id and type) before saving, so a
cached payload cannot be repointed at an unrelated datasource. Payloads
without a parseable datasource fall back to the chart's datasource at
execution time and are left unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@rusackas rusackas force-pushed the fix/chart-query-context-datasource-validation branch from d544bff to 1c438a5 Compare June 13, 2026 13:40
Comment thread superset/commands/chart/exceptions.py
Comment thread tests/unit_tests/commands/chart/update_test.py
Comment thread superset/commands/chart/update.py Outdated
A datasource object with a matching id but no type was treated as valid,
but query-context loading reads datasource["type"] directly and would
raise KeyError when the saved context is later replayed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bito-code-review

bito-code-review Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #1ef6c1

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 1c438a5..c8b9e99
    • superset/commands/chart/exceptions.py
    • superset/commands/chart/update.py
    • tests/unit_tests/commands/chart/update_test.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants