Repository navigation
fix(schemas): rename deprecated query fields regardless of falsy values - #41263
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 <[email protected]>
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% 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
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. |
…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.
|
Bito Automatic Review Skipped – PR Already Merged |
…es (apache#41263) (cherry picked from commit 5bbab86)
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.