Repository navigation
fix(core): return 400 instead of 500 on malformed time ranges in temporal filters (#45459) - #45822
FrancescoCastaldi wants to merge 3 commits into
Conversation
…oral filters (apache#45459) When a temporal filter carries an unparseable time range (e.g. 'a : b' or inverted date boundaries), get_since_until_from_time_range raises TimeRangeParseFailError or ValueError uncaught inside get_sqla_query and processing_time_offsets. This bypassed query validation handlers and surfaced as HTTP 500. This patch: - Catches TimeRangeParseFailError, TimeRangeAmbiguousError, ValidationError, and ValueError across get_sqla_query and processing_time_offsets. - Converts the failure to QueryObjectValidationError naming the invalid column. - Adds comprehensive unit tests in tests/unit_tests/models/helpers_test.py. Fixes apache#45459 Signed-off-by: Francesco Castaldi <info@francescocastaldi.it>
|
Heads up, #45461 has been open for this since Oct 19 and is linked on the The only difference I can see is where the date-range offset is caught. You No preference on which lands, just flagging so we don't both carry it. The |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45822 +/- ##
==========================================
+ Coverage 84.57% 84.63% +0.06%
==========================================
Files 3069 3068 -1
Lines 205228 205617 +389
Branches 48222 48317 +95
==========================================
+ Hits 173571 174033 +462
+ Misses 28353 28292 -61
+ Partials 3304 3292 -12
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:
|
…ers and pot drift (apache#45822) Signed-off-by: Francesco Castaldi <info@francescocastaldi.it>
Executive Summary & Review Feedback ResolutionAll feedback from @sadpandajoe on PR #45822 has been addressed, verified, and pushed to origin in commit 1. Addressed Review Items & Foresight Anticipation
2. Modified Files & Test Coverage
3. Evidence Gate & Quality Checks
@sadpandajoe, all requested test improvements and CI fixes are in place. The PR is ready for your re-review whenever you have a moment, thank you! |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| TimeRangeParseFailError, | ||
| TimeRangeAmbiguousError, | ||
| ValidationError, | ||
| ValueError, |
There was a problem hiding this comment.
A secondary temporal filter like "2024-01-01T00:00:00Z : 2024-01-02" still returns a 500: get_since_until compares an offset-aware _since with a naive _until (_since > _until) and raises TypeError, which isn't in this tuple, so it escapes the new handler. The same gap applies to the other guards added here. Should TypeError be caught too, or is mixed-timezone input intentionally out of scope for this fix?
There was a problem hiding this comment.
In commit 089c8d37a4, we addressed this by adding TypeError to the caught exception tuple across all three get_since_until_from_time_range call sites in superset/models/helpers.py (lines 3089, 3227, and 7027). When mixed offset-naive and offset-aware datetimes like "2024-01-01T00:00:00Z : 2024-01-02" are passed, get_since_until raises a TypeError during timestamp comparison (_since > _until). This is now properly intercepted and converted into a QueryObjectValidationError, consistently returning 400 instead of 500.
Additionally, we formatted the exception statement in superset/models/helpers.py to satisfy ruff-format (resolving the pre-commit (current) CI failure) and added a dedicated regression unit test in tests/unit_tests/models/helpers_test.py verifying mixed-timezone temporal ranges.
…at helpers.py (apache#45822) Signed-off-by: Francesco Castaldi <info@francescocastaldi.it>
Review Follow-Up & CI RemediationAll review comments and CI checks have been addressed in commit
@sadpandajoe, this is ready for your re-review whenever you have a chance. Thank you! |
SUMMARY
Fixes #45459.
When a temporal filter carries an unparseable time range (such as
"a : b"or inverted date bounds like"2024-02-01 : 2024-01-01"),get_since_until_from_time_rangeraisesTimeRangeParseFailError(subclass of marshmallowValidationError) orValueError.When such an invalid time range is present in a secondary temporal filter or during date-range timeshift processing:
get_sqla_query, the parse failure was uncaught and escaped the query validation handlers, reaching the global Flask error handler and returning HTTP 500 instead of HTTP 400.processing_time_offsets, relative and date-range offsets experienced similar uncaught parse errors.This change:
(TimeRangeParseFailError, TimeRangeAmbiguousError, ValidationError, ValueError)acrossget_sqla_queryandprocessing_time_offsets.QueryObjectValidationErrornaming the invalid column, enablingQueryContextProcessorto return an informative 400 Bad Request.tests/unit_tests/models/helpers_test.py.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (Backend API error handling)
TESTING INSTRUCTIONS
Run unit tests:
ADDITIONAL INFORMATION