SEPURI-SAI-KRISHNA opened a new pull request, #42410:
URL: https://github.com/apache/superset/pull/42410
### SUMMARY
`SqlaTable.exec_query` converts only `InvalidPostProcessingError` into a
`QueryObjectValidationError` (→ 400). Anything else raised during
post-processing escapes as an unhandled 500. Two separate defects did exactly
that for malformed `post_processing` input on `POST /api/v1/chart/data`.
**1. `select`'s `exclude` option was never validated.**
```python
@validate_column_args("columns", "drop", "rename") # "drop" is not a
parameter
def select(df, columns=None, exclude=None, rename=None):
```
`validate_column_args` only inspects argnames that appear in the options, so
naming a non-existent `"drop"` meant `exclude` was unchecked and
`df.drop(exclude, axis=1)` raised a raw `KeyError`:
```json
{"operation": "select", "options": {"exclude": ["does_not_exist"]}}
```
→ `KeyError: "['does_not_exist'] not found in axis"`, surfacing as a 500.
I ran an AST scan over every `@validate_column_args` usage in the tree; this
is the only decorator/signature mismatch.
Fixing the name alone left a sibling 500 in the same function: `exclude` is
applied *after* the `columns` projection, so `columns=["y"],
exclude=["label"]`
passes validation against the incoming DataFrame and then `KeyError`s on the
narrowed one. That path is now a validation error too. The `exclude`
docstring
claimed post-rename names should be referenced, which is backwards — it is
applied before `rename` — so it is corrected.
**2. A malformed i18n placeholder broke the unsupported-operation error.**
```python
_("Unsupported post processing operation: %(operation)s", type=operation)
```
`flask_babel.gettext` does `string % variables`, so this raised
`KeyError: 'operation'` *while constructing* `InvalidPostProcessingError`.
The
intended 400 never surfaced. I AST-scanned every `_()` / `__()` call in
`superset/` for placeholder/kwarg mismatches; this was the only fatal one.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable — API error handling, no UI change.
### TESTING INSTRUCTIONS
```bash
pytest tests/unit_tests/pandas_postprocessing/test_select.py \
tests/unit_tests/queries/query_object_test.py
```
Adds `test_select_invalid_exclude` plus two `exec_post_processing` tests. To
confirm they are genuine regression tests, revert the two source changes and
re-run:
- `select(df, exclude=["abc"])` → `KeyError: "['abc'] not found in axis"`
- unsupported operation → `KeyError: 'operation'` raised from `flask_babel`
Behaviour after the change — every previously-valid call is unchanged:
| call | result |
|---|---|
| `exclude=["abc"]` | `InvalidPostProcessingError` (was `KeyError`) |
| `exclude=["label"]` | `["y"]` |
| `rename={"y":"y1"}, exclude=["label"]` | `["y1"]` |
| `columns=["y"], exclude=["label"]` | `InvalidPostProcessingError` (was
`KeyError`) |
| `columns=["y","label"], exclude=["label"]` | `["y"]` |
| `columns=["y","label"]` | `["y", "label"]` |
Wider sweep, no regressions:
```bash
pytest tests/unit_tests/common/ tests/unit_tests/queries/
tests/unit_tests/pandas_postprocessing/
```
(`test_prophet.py` fails locally only because `prophet` is an optional extra
that is not installed; unrelated to this change.)
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] 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]