SEPURI-SAI-KRISHNA opened a new pull request, #45461:
URL: https://github.com/apache/superset/pull/45461

   ### SUMMARY
   
   Fixes #45459.
   
   Only one temporal filter is parsed while the query context is built, where a
   range Superset cannot parse is answered as a 400. The SQL-building and
   time-comparison paths parse every temporal filter, and they run outside the
   handlers that answer 400, so the same range in a second filter escaped as a
   500.
   
   `get_since_until_from_temporal_filter` parses a filter's range and reports a 
bad
   one as `QueryObjectValidationError`, naming the column so the offending 
filter
   can be found. Three call sites move onto it:
   
   - `get_sqla_query`, which parses each `TEMPORAL_RANGE` filter while building 
the
     WHERE clause
   - `processing_time_offsets`, where the enclosing range is read from the last
     temporal filter before the method's own try begins
   - `processing_time_offsets` again, where a relative offset shifts each 
temporal
     filter in turn
   
   `TimeRangeParseFailError` and `TimeRangeAmbiguousError` are marshmallow
   `ValidationError`s rather than `ValueError`s, so both are caught; the 
remaining
   failures arrive as a bare `ValueError`. The fourth parse site, the date-range
   offset, already does this inline and is left as it is: `is_valid_date_range`
   has pinned the format down by the time it runs.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   The real `get_sqla_query` on a dataset with two temporal columns, changing 
only
   the second filter's range:
   
   Before:
   
   ```
   sane second range:          built SQL ok
   'a : b':                    500 TimeRangeParseFailError: Cannot parse time 
string [a]
   '2024-02-01 : 2024-01-01':  500 ValueError: From date cannot be larger than 
to date
   ```
   
   After:
   
   ```
   sane second range:          built SQL ok
   'a : b':                    400 Invalid time range for other_ds: Cannot 
parse time string [a]
   '2024-02-01 : 2024-01-01':  400 Invalid time range for other_ds: From date 
cannot be larger than to date
   ```
   
   The same range in the first filter was a 400 before this change and still is.
   
   ### TESTING INSTRUCTIONS
   
   ```
   pytest tests/unit_tests/common/test_time_range_utils.py \
          tests/unit_tests/models/helpers_test.py -k temporal
   ```
   
   The four new behaviour tests cover both `get_sqla_query` and both parse 
sites in
   `processing_time_offsets`, and each fails without the change.
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: #45459
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to