eschutho opened a new pull request, #44463:
URL: https://github.com/apache/superset/pull/44463

   ### SUMMARY
   
   Post-processing operators (e.g. `resample`) dispatched by 
`exec_post_processing` in `ExploreMixin.get_query_result` can raise raw 
`TypeError` or `pandas.errors.DataError` from their underlying pandas calls 
when the DataFrame contains non-numeric (object-dtype) columns alongside 
numeric metrics.
   
   **Example**: `resample` with `method="mean"` on a DataFrame that includes a 
string dimension column causes `df.resample(rule).mean()` to raise `TypeError: 
agg function failed [how->mean,dtype->object]`. Similarly, `rolling` with 
non-numeric columns raises `pandas.errors.DataError: Cannot aggregate 
non-numeric type: object`.
   
   The existing `except InvalidPostProcessingError` clause does not catch these 
raw exceptions, so they propagate through the chart-data REST API path and 
produce an opaque 500 instead of a clean 400.
   
   **Fix**: Widen the `except` in `get_query_result` to also catch `TypeError` 
and `pd.errors.DataError` and re-raise them as `QueryObjectValidationError` 
with the same 400 semantics as the existing arm. This is a two-line additive 
change at the call-site boundary — no operator internals modified.
   
   Precedent: apache/superset#43081 and apache/superset#44011 follow the same 
"wrap raw exception as `QueryObjectValidationError` at a chart-data boundary" 
pattern.
   
   Note for future: `superset/semantic_layers/models.py:364` has the identical 
narrow-catch pattern and is a candidate for a follow-up fix.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A — backend-only fix; error response changes from HTTP 500 to HTTP 400 
with a human-readable message.
   
   ### TESTING INSTRUCTIONS
   
   1. Regression test added in 
`tests/unit_tests/models/helpers_test.py::test_get_query_result_wraps_post_processing_type_error`.
   2. The test uses a `QueryObject` with `post_processing=[{"operation": 
"resample", "options": {"method": "mean", "rule": "1D"}}]` on a DataFrame with 
a DatetimeIndex and an `object`-dtype column. Without the fix the test fails 
with `TypeError`; with the fix it asserts `QueryObjectValidationError` is 
raised.
   3. Run: `pytest 
tests/unit_tests/models/helpers_test.py::test_get_query_result_wraps_post_processing_type_error`
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] 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