eschutho opened a new pull request, #44802:
URL: https://github.com/apache/superset/pull/44802
### SUMMARY
**Root cause:** `DatabaseRestApi.validate_parameters` (the `POST
/api/v1/database/validate_parameters/` endpoint) catches marshmallow
`ValidationError` and builds `SupersetError` objects by joining the error
messages with `"\n".join(messages)`. However, the field validators in
`superset/databases/schemas.py` — specifically `extra_validator` — raise
`ValidationError` with messages produced by `lazy_gettext()` (imported as `_`),
which returns `LazyString` proxy objects, not native `str` instances.
`str.join()` performs an `isinstance(x, str)` check on each sequence item and
rejects `LazyString`, causing a `TypeError: sequence item 0: expected str
instance, LazyString found`. This turns what should be a clean 422 validation
response into an unhandled 500 for the caller.
One concrete trigger: POSTing `extra` with `{"metadata_cache_timeout":
{"schema_cache_timeout": -1}}` hits the negative-integer validation in
`extra_validator` (~line 343 of `schemas.py`), which raises
`ValidationError([_("The %(key)s in metadata_cache_timeout must be a
non-negative integer.", key=key)])`.
**Fix:** Change `"\n".join(messages)` to `"\n".join(str(m) for m in
messages)` in the `validate_parameters` method. `LazyString.__str__()` resolves
to the translated text, so the resulting message content is identical — the
endpoint just no longer crashes.
### Tradeoffs
This fix does not change any user-visible behavior or semantics. The
resolved message text is identical before and after the fix — it simply no
longer crashes. The only observable change is that a 500 Internal Server Error
becomes the intended 422 validation error response. There is no failure-mode
semantics change to disclose beyond "a 500 becomes the intended 422."
### Follow-up candidates
Grep of the codebase found no other instances of `"\n".join(messages)` over
marshmallow `ex.messages` values. This was the only occurrence of this bug
pattern.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable (API-only change, no UI).
**Before:** `POST /api/v1/database/validate_parameters/` with invalid
`extra.metadata_cache_timeout` returns `500 Internal Server Error` with
`TypeError: sequence item 0: expected str instance, LazyString found`.
**After:** The same request returns `422` with a proper JSON error body
containing the translated validation message.
### TESTING INSTRUCTIONS
1. A new integration test
`test_validate_parameters_extra_metadata_cache_timeout_invalid` was added
alongside the existing `test_validate_parameters_*` tests.
2. The test POSTs a payload with `{"metadata_cache_timeout":
{"schema_cache_timeout": -1}}` in `extra` and asserts the endpoint returns 422
with the expected error structure.
3. **Fail-before evidence:** With the original `"\n".join(messages)` code,
the test fails with `assert 500 == 422` — the server logs show `TypeError:
sequence item 0: expected str instance, LazyString found`.
4. **Pass-after evidence:** With the fix applied (`"\n".join(str(m) for m in
messages)`), the test passes — all 8 `test_validate_parameters_*` tests pass
with no regressions.
5. Ruff check and format pass cleanly on both changed files.
### 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
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]