Skip to content

fix(examples): rewrite chart datasource references on import - #45378

Merged
villebro merged 3 commits into
apache:masterfrom
villebro:villebro/fix-examples-chart-datasource-refs
Oct 16, 2026
Merged

villebro merged 3 commits into
apache:masterfrom
villebro:villebro/fix-examples-chart-datasource-refs

Conversation

@villebro

@villebro villebro commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

The examples importer only updated the datasource_id, datasource_type and datasource_name columns when binding a chart to its dataset, so the stale dataset id kept in the exported chart params (e.g. 21__table in Total_Revenue.yaml) survived load-examples. Explore hides this because Slice.form_data takes the datasource from the row, but code that reads params directly queries the wrong dataset.

This makes the examples importer use update_chart_config_dataset to rewrite those references, as the chart, dashboard and assets importers already do.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

Run pytest tests/unit_tests/commands/importers/v1/examples_test.py. test_import_rewrites_stale_chart_datasource_reference imports a chart with a stale dataset id in its params and asserts it is rewritten to the imported dataset; it fails without this change.

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

The examples importer bound each chart to its dataset by updating only the datasource_id, datasource_type and datasource_name columns. The datasource reference kept in the chart's params (and in its query_context, when present) kept the id from the instance the fixture was exported from, so after load-examples a chart's params could name a different dataset than the chart row. Explore hides this because Slice.form_data takes the datasource from the row, but code that reads params directly queried the wrong dataset. The importer now uses update_chart_config_dataset, as the chart, dashboard and assets importers already do.
Import a database, dataset and chart through the examples importer against the in-memory session and check that the chart's datasource_id and params follow the imported dataset instead of the stale id in the exported params. Drop the equivalent assertions from the mocked wiring test.
@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt PR Risk: Low Risk

  • The PR appears safe to merge; imported charts now update datasource references alongside datasource fields.
  • The test verifies that both the chart datasource ID and the reference in params point to the imported dataset.

Assessed commit: 996dd5b7f16f

@pull-request-size pull-request-size Bot added size/M and removed size/S labels Oct 16, 2026
Name the stale id in the chart params as a constant that no import into a fresh database can assign, instead of 21, and drop the guard assertion that the new id differs from it.

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified against master. The examples importer only did config.update(dataset_info[...]), so params["datasource"] kept the exported id (21__table) while the datasource_id column was rebound. update_chart_config_dataset also rewrites params["datasource"] and the query_context datasource, form_data and per-query references, and it is the same helper the chart importer (commands/chart/importers/v1/__init__.py), dashboard importer and assets importer already use. The examples importer was the only one missing it. The test imports a chart with a stale id in params and asserts both datasource_id and params["datasource"] point at the imported dataset.

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.49%. Comparing base (ad63b3e) to head (1df5799).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #45378   +/-   ##
=======================================
  Coverage   83.49%   83.49%           
=======================================
  Files        3047     3047           
  Lines      199516   199523    +7     
  Branches    46552    46554    +2     
=======================================
+ Hits       166589   166597    +8     
+ Misses      29701    29699    -2     
- Partials     3226     3227    +1     
Flag Coverage Δ
hive 34.97% <0.00%> (-0.01%) ⬇️
mysql 52.93% <50.00%> (-0.01%) ⬇️
postgres 52.93% <50.00%> (-0.01%) ⬇️
presto 36.72% <0.00%> (-0.01%) ⬇️
python 87.01% <100.00%> (+<0.01%) ⬆️
sqlite 52.69% <50.00%> (-0.01%) ⬇️
unit 81.05% <100.00%> (+<0.01%) ⬆️

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.

@villebro
villebro merged commit 19bb094 into apache:master Oct 16, 2026
74 checks passed
@villebro
villebro deleted the villebro/fix-examples-chart-datasource-refs branch October 16, 2026 18:50
villebro added a commit that referenced this pull request Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants