fix(schemas): rename deprecated query fields regardless of falsy values#41263
fix(schemas): rename deprecated query fields regardless of falsy values#41263eschutho wants to merge 1 commit into
Conversation
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 <noreply@anthropic.com>
Code Review Agent Run #9098f1Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #41263 +/- ##
==========================================
- Coverage 64.36% 55.66% -8.70%
==========================================
Files 2653 2653
Lines 144864 144867 +3
Branches 33421 33421
==========================================
- Hits 93242 80647 -12595
- Misses 49949 63486 +13537
+ Partials 1673 734 -939
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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. |
What's the change?
ChartDataQueryObjectSchema.rename_deprecated_fields()is a Marshmallow@post_loadhook that renames legacy query field names to their modern equivalents:timeseries_limitseries_limittimeseries_limit_metricseries_limit_metricgranularity_sqlagranularitygroupbycolumnsThe original implementation used the walrus operator with a truthiness check:
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=Noneorgranularity_sqla=None(all four deprecated fields carryallow_none=True)Result: the renamed field (
series_limit) is silently absent from thedatadict passed toQueryObject.QueryObject.__init__falls back to itsseries_limit: int = 0default — numerically the same but semantically wrong; the caller's explicit0orNoneis discarded.Fix:
old in data— checks key presence, not value truthinessdata.pop(old)— always removes the deprecated keydata.setdefault(new, ...)— sets the new key only if it isn't already present (an explicitseries_limitfrom the caller is never silently clobbered by a coexisting deprecatedtimeseries_limit)No behavior change for truthy values
For any truthy value the behavior is identical to the old code.
Test plan
ChartDataQueryObjectSchema: verify thattimeseries_limit=0is renamed toseries_limit=0after deserialization (was silently discarded before).query_context_tests.pytests that set deprecated fields to ensure they still pass.Follow-up (non-blocking)
QueryObject._rename_deprecated_fields(query_object.py:232) has the sameif value:guard for thesetattrpath. The deprecation warning still fires there regardless (the log line precedes theif), and the functional outcome is identical sinceseries_limitdefaults to0. A follow-up fix there would make both rename paths consistent.