Skip to content

fix(examples): replace deprecated granularity_sqla with granularity - #43432

Merged
eschutho merged 2 commits into
masterfrom
fix/examples-granularity-sqla
Aug 27, 2026
Merged

eschutho merged 2 commits into
masterfrom
fix/examples-granularity-sqla

Conversation

@eschutho

Copy link
Copy Markdown
Member

Summary

superset/common/query_object.py's DEPRECATED_FIELDS list warns and performs a runtime migration whenever legacy form_data key granularity_sqla is present (current name: granularity). The birth_names and world_bank example datasets — both the Python seed scripts and their YAML chart-config siblings — still constructed slice params using the old key, so every superset load_examples run (and every render of those charts) logged this deprecation warning.

This mirrors the scope of #43422, which did the identical rename for the sibling deprecated field timeseries_limit_metric across the same .py + .yaml pairs.

What changed

  • superset/examples/birth_names.py, superset/examples/world_bank.py: renamed granularity_sqla → granularity (8 occurrences).
  • superset/examples/usa_births_names/charts/*.yaml (11 files), superset/examples/world_health/charts/*.yaml (9 files): same rename, since load_examples_from_configs() loads these unconditionally alongside the Python loaders.

Decisions made that were not in the instructions

None.

No-behavior-change note

get_slice_json() (superset/examples/helpers.py) is a plain dict merge with no schema validation, and the YAML configs are loaded as plain dicts too. granularity is the field DEPRECATED_FIELDS migrates granularity_sqla into at read time, so this is a pure key rename — the resulting slice/chart params are identical once loaded, just constructed via the current field name instead of triggering the legacy-field warning + migration path.

Test plan

  • ruff check / ruff format --check on both changed .py files: clean.
  • All 20 changed .yaml files parse successfully via yaml.safe_load.
  • Verified zero remaining granularity_sqla occurrences in the changed files, and confirmed the unrelated granularity_sqla_override variable in superset/utils/core.py (different dict, extra_form_data) was untouched.
  • Searched tests/ for any assertion hardcoding granularity_sqla against birth_names.create_slices/world_bank.create_slices output specifically — none found.

Superset.common.query_object.DEPRECATED_FIELDS logs a warning and
performs a runtime migration whenever granularity_sqla is present in
form_data. The birth_names and world_bank example datasets still
seeded slices using the old field name, triggering this warning on
every load. get_slice_json() is a plain dict merge with no schema
validation, so the rename is a straight drop-in with no behavior
change once the examples are (re)loaded.
Self-review on the prior commit caught that the same slices also ship
as YAML fixtures under examples/usa_births_names/charts and
examples/world_health/charts, loaded unconditionally by
load_examples_from_configs() on every `superset load_examples` run.
Those still used the old granularity_sqla key, so the deprecation
warning would keep firing via that path even after the .py rename.
Mirrors the scope of the merged precedent (#43422),
which covered both the .py and .yaml sides of the same pattern.
@dosubot dosubot Bot added the doc:examples Related to example datasets and dashboards label Aug 23, 2026
@bito-code-review

bito-code-review Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #48770e

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/examples/usa_births_names/charts/Girl_Name_Cloud.yaml - 1
    • Inconsistent deprecation migration · Line 31-31
      The replacement of deprecated `granularity_sqla` with `granularity` is correct per `DeprecatedField` definitions in `superset/common/query_object.py` line 69. However, ~46 other example YAML files in the repository (e.g., `superset/examples/slack_dashboard/charts/`, `superset/examples/fcc_new_coder_survey/charts/`) still use `granularity_sqla`. This creates inconsistency within the same example dataset. For comprehensive migration, either update all files or document this as an incremental fix.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/examples/world_bank.py - 1
Review Details
  • Files reviewed - 22 · Commit Range: 2ebddb2..271cdd4
    • superset/examples/birth_names.py
    • superset/examples/usa_births_names/charts/Boy_Name_Cloud.yaml
    • superset/examples/usa_births_names/charts/Boys.yaml
    • superset/examples/usa_births_names/charts/Genders.yaml
    • superset/examples/usa_births_names/charts/Genders_by_State.yaml
    • superset/examples/usa_births_names/charts/Girl_Name_Cloud.yaml
    • superset/examples/usa_births_names/charts/Girls.yaml
    • superset/examples/usa_births_names/charts/Participants.yaml
    • superset/examples/usa_births_names/charts/Pivot_Table_v2.yaml
    • superset/examples/usa_births_names/charts/Top_10_Boy_Name_Share.yaml
    • superset/examples/usa_births_names/charts/Top_10_Girl_Name_Share.yaml
    • superset/examples/usa_births_names/charts/Trends.yaml
    • superset/examples/world_bank.py
    • superset/examples/world_health/charts/Box_plot.yaml
    • superset/examples/world_health/charts/Growth_Rate.yaml
    • superset/examples/world_health/charts/Life_Expectancy_VS_Rural.yaml
    • superset/examples/world_health/charts/Most_Populated_Countries.yaml
    • superset/examples/world_health/charts/Rural.yaml
    • superset/examples/world_health/charts/Rural_Breakdown.yaml
    • superset/examples/world_health/charts/Treemap.yaml
    • superset/examples/world_health/charts/World_s_Pop_Growth.yaml
    • superset/examples/world_health/charts/World_s_Population.yaml
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

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

  • /review - Manually triggers an incremental AI Review.

  • /review full - 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

@codecov

codecov Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.85%. Comparing base (9f505eb) to head (271cdd4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43432      +/-   ##
==========================================
- Coverage   78.85%   78.85%   -0.01%     
==========================================
  Files        2876     2876              
  Lines      164581   164581              
  Branches    38011    38011              
==========================================
- Hits       129786   129784       -2     
- Misses      32348    32350       +2     
  Partials     2447     2447              
Flag Coverage Δ
hive 38.08% <ø> (ø)
mysql 57.77% <ø> (ø)
postgres 57.80% <ø> (-0.01%) ⬇️
presto 40.01% <ø> (ø)
python 83.54% <ø> (-0.01%) ⬇️
sqlite 57.49% <ø> (ø)
unit 73.56% <ø> (-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.

"compare_suffix": "o10Y",
"limit": "25",
"granularity_sqla": "ds",
"granularity": "ds",

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.

Suggestion: The modern granularity key is not handled when rebuilding a big_number query from saved form data: form_data_query_context._columns_and_metrics only promotes granularity_sqla to the time column. Consequently, exports or fallback query paths for the Participants trendline produce an aggregate without the ds column and lose the trendline time series. Update the rebuild logic to recognize granularity as well, or retain the legacy key until that consumer is updated. [api mismatch]

Severity Level: Major ⚠️
- ❌ Birth names Big Number exports lose trendline time columns.
- ⚠️ Excel fallback queries return one aggregate instead of a series.
- ⚠️ Other modern-key Big Number fallback charts share this mismatch.

Use CodeAnt Skill

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/examples/birth_names.py
**Line:** 179:179
**Comment:**
	*Api Mismatch: The modern `granularity` key is not handled when rebuilding a `big_number` query from saved form data: `form_data_query_context._columns_and_metrics` only promotes `granularity_sqla` to the time column. Consequently, exports or fallback query paths for the Participants trendline produce an aggregate without the `ds` column and lose the trendline time series. Update the rebuild logic to recognize `granularity` as well, or retain the legacy key until that consumer is updated.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The PR replaces granularity_sqla with granularity in various configuration files, but the backend logic that rebuilds queries from saved form data (specifically _columns_and_metrics) is not yet updated to recognize the new granularity key. This causes the time column to be dropped in certain query paths, leading to the loss of trendline time series.

To resolve this, you should update the query rebuilding logic to check for granularity if granularity_sqla is missing. Since I do not have access to the specific file containing the _columns_and_metrics logic, I recommend searching your codebase for that attribute and adding a fallback:

# Example of the required logic update
granularity = form_data.get("granularity") or form_data.get("granularity_sqla")

There are no other comments in the provided PR review data to address.

superset/examples/birth_names.py

granularity = form_data.get("granularity") or form_data.get("granularity_sqla")

@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.

Review: fix(examples): replace deprecated granularity_sqla with granularity (head 271cdd45)

Reviewed as a behavior change, not a rename. Verdict on the one open codeant-ai thread at birth_names.py:179: CONFIRMED — but the blast radius is much narrower than "the charts lose their time column."

The codeant claim is structurally correct

superset/common/form_data_query_context.py:256-257 promotes the time column into columns for a Big Number trendline using only granularity_sqla:

if not columns and viz_type == "big_number" and form_data.get("granularity_sqla"):
    return [form_data["granularity_sqla"]], metrics

Contrast :349, which correctly accepts both keys for the primary granularity job:

if granularity := form_data.get("granularity") or form_data.get("granularity_sqla"):

Executable proof at head (RAN — build_query_context_from_form_data, viz_type big_number):

OLD granularity_sqla -> columns: ['ds'] | granularity: ds
NEW granularity      -> columns: []     | granularity: ds

So after the rename, a big_number trendline no longer groups by its time column when its query context is rebuilt from form data — it returns a single aggregate instead of the trend series. This hits Participants in both birth_names.py and usa_births_names/charts/Participants.yaml (viz_type: big_number, granularity: ds).

…but normal chart rendering is NOT affected

build_query_context_from_form_data is called from only two places (traced, grep over superset/): the MCP chart tools (mcp_service/chart/tool/get_chart_preview.py, get_chart_sql.py) and Excel dashboard export (tasks/export_dashboard_excel.py). Standard /chart/data rendering does not use it — it relies on the stored query context / frontend buildQuery, where granularity is the canonical modern key (query_object.py:69 DeprecatedField(old_name="granularity_sqla", new_name="granularity") renames the legacy key, and extractExtras.ts reads granularity). The headline Big Number value is still correct; only the rebuilt-trendline groupby is dropped, and only in those two auxiliary paths.

Net: the rename direction is right (granularity is the officially deprecated-away key). The PR just exposes a pre-existing gap in _columns_and_metrics, which should mirror :349:

if not columns and viz_type == "big_number" and (
    gran := form_data.get("granularity") or form_data.get("granularity_sqla")
):
    return [gran], metrics

Worth bundling here (one line) or filing as a fast follow, since this PR is what makes the modern-key big_number reach that branch.

Test adequacy (Rule 26) — the useful part

No test in this diff, and no existing test would catch this. tests/unit_tests/common/test_form_data_query_context.py covers the promotion (test_big_number_trendline_promotes_granularity_sqla_column, :142) but exclusively with the granularity_sqla key — there is no case exercising the modern granularity key for the big_number branch. I RAN the file at head: 40 passed — and they pass precisely because they never test the path this PR moves the examples onto. CI green here is evidence of absent coverage, not of correctness. Adding a granularity-key variant of that test (or fixing :256 and asserting it) would close the hole.

Supporting notes (non-blocking)

  • Partial rename. Many example dashboards still carry granularity_sqla (video_game_sales/*, fcc_new_coder_survey/*, sales_dashboard/*, slack_dashboard/*, deckgl_demo/*, misc_charts/*). This PR scopes to the birth-names and world-health/world-bank dashboards; each is internally consistent, and both keys render fine, so this is acceptable — but the repo now runs both keys in parallel, and (ironically) the un-migrated granularity_sqla big_numbers still promote correctly in the rebuild path while the migrated ones don't, until :256 is fixed.
  • "Deprecated" is partly aspirational. Besides :256, utils/core.py's native-filter path also reads the chart's own key exclusively (chart_has_granularity_sqla = bool(form_data.get("granularity_sqla")), :1183). Not exercised by simply loading examples, but it confirms granularity_sqla is not uniformly shimmed in code.

Gate status

CI re-derived at post time via statusCheckRollup: 63 CheckRun SUCCESS + 1 StatusContext SUCCESS, 3 NEUTRAL, 14 SKIPPED — no IN_PROGRESS, zero failures. This is a COMMENT round, not an approval or a change request. The codeant thread is a real (if narrow) finding; I'll leave it for a committer to resolve or action.

@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.

agent left non blocking comments i will leave to your call. approving as all else checks out

@eschutho
eschutho merged commit 9f62aac into master Aug 27, 2026
81 checks passed
@eschutho
eschutho deleted the fix/examples-granularity-sqla branch August 27, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc:examples Related to example datasets and dashboards preset-io size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants