Skip to content

fix(schemas): rename deprecated query fields regardless of falsy values - #41263

Merged
eschutho merged 2 commits into
apache:masterfrom
eschutho:fix/query-object-schema-rename-falsy
Jul 2, 2026
Merged

eschutho merged 2 commits into
apache:masterfrom
eschutho:fix/query-object-schema-rename-falsy

Conversation

@eschutho

Copy link
Copy Markdown
Member

What's the change?

ChartDataQueryObjectSchema.rename_deprecated_fields() is a Marshmallow @post_load hook that renames legacy query field names to their modern equivalents:

Old (deprecated) New
timeseries_limit series_limit
timeseries_limit_metric series_limit_metric
granularity_sqla granularity
groupby columns

The original implementation used the walrus operator with a truthiness check:

if value := data.pop(old, None):
    data[new] = value

Bug: data.pop(old, None) always removes the old key, but when the value is falsy, the new key is never set. Real-world cases silently affected:

  • timeseries_limit=0 — the default for most charts meaning "no series limit"
  • groupby=[] — explicit empty groupby (fields.List(...), empty list is falsy)
  • timeseries_limit_metric=None or granularity_sqla=None (all four deprecated fields carry allow_none=True)

Result: the renamed field (series_limit) is silently absent from the data dict passed to QueryObject. QueryObject.__init__ falls back to its series_limit: int = 0 default — numerically the same but semantically wrong; the caller's explicit 0 or None is discarded.

Fix:

for old, new in _renames:
    if old in data:
        data.setdefault(new, data.pop(old))
  • old in data — checks key presence, not value truthiness
  • data.pop(old) — always removes the deprecated key
  • data.setdefault(new, ...) — sets the new key only if it isn't already present (an explicit series_limit from the caller is never silently clobbered by a coexisting deprecated timeseries_limit)

No behavior change for truthy values

For any truthy value the behavior is identical to the old code.

Test plan

  • Unit tests for ChartDataQueryObjectSchema: verify that timeseries_limit=0 is renamed to series_limit=0 after deserialization (was silently discarded before).
  • Integration test: run the existing query_context_tests.py tests that set deprecated fields to ensure they still pass.

Follow-up (non-blocking)

QueryObject._rename_deprecated_fields (query_object.py:232) has the same if value: guard for the setattr path. The deprecation warning still fires there regardless (the log line precedes the if), and the functional outcome is identical since series_limit defaults to 0. A follow-up fix there would make both rename paths consistent.

ChartDataQueryObjectSchema.rename_deprecated_fields() used a walrus
operator truthiness check (`if value := data.pop(old, None)`), which
silently skipped the rename whenever the deprecated field value was
falsy — most commonly timeseries_limit=0, meaning "no series limit."

The old key then reached QueryObject.__init__ unchanged, triggering the
_rename_deprecated_fields deprecation warning on every such chart render.

Fix: check key presence (old in data) rather than value truthiness.
Use setdefault so an explicit new-key value from the caller wins.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@dosubot dosubot Bot added the viz:charts Namespace | Anything related to viz types label Jun 20, 2026
@bito-code-review

bito-code-review Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #9098f1

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 0be66d4..0be66d4
    • superset/charts/schemas.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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@netlify

netlify Bot commented Jun 20, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 0be66d4
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a36be27aaa634000844286d
😎 Deploy Preview https://deploy-preview-41263--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@eschutho
eschutho requested a review from betodealmeida June 20, 2026 16:23
@codecov

codecov Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.15%. Comparing base (382a094) to head (d2b6561).
⚠️ Report is 346 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41263      +/-   ##
==========================================
- Coverage   64.36%   64.15%   -0.22%     
==========================================
  Files        2653     2673      +20     
  Lines      144864   147332    +2468     
  Branches    33421    33761     +340     
==========================================
+ Hits        93242    94518    +1276     
- Misses      49949    51069    +1120     
- Partials     1673     1745      +72     
Flag Coverage Δ
hive 39.23% <100.00%> (-0.10%) ⬇️
mysql 57.83% <100.00%> (-0.23%) ⬇️
postgres 57.89% <100.00%> (-0.23%) ⬇️
presto 40.77% <100.00%> (-0.15%) ⬇️
python 59.28% <100.00%> (-0.28%) ⬇️
sqlite 57.47% <100.00%> (-0.31%) ⬇️
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.

@durgaprasadml

Copy link
Copy Markdown
Contributor

Thanks for the fix. The previous implementation relied on truthiness checks and could unintentionally drop valid falsy values such as 0, [], or None during field renaming. Checking key presence instead of value truthiness looks correct and preserves the intended behavior.

One thing that may be worth adding is a test covering the case where both the deprecated and modern field names are supplied simultaneously (e.g. timeseries_limit and series_limit) to explicitly document the expected precedence behavior.

…ll handling falsy values

The setdefault-based rename in the prior commit fixed the falsy-value bug
(timeseries_limit=0) but changed the groupby->columns merge behavior: it
now preserves an existing `columns` value instead of letting `groupby`
overwrite it, which regressed test_time_offset_comparison_queries_use_chart_row_limit
and its sibling (both rely on groupby overwriting columns) and
test_chart_data_query_object_schema_deprecated_fields_renamed's
"groupby overwrites columns when both are provided" case.

Restore the overwrite semantics for all four renames, but treat 0 as a
meaningful value (not just non-empty/non-None) so timeseries_limit=0
still renames to series_limit=0 - fixing the original falsy-pop bug
without touching the overwrite behavior other tests depend on.
@eschutho
eschutho merged commit 5bbab86 into apache:master Jul 2, 2026
59 checks passed
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

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

Labels

size/XS viz:charts Namespace | Anything related to viz types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants