EnxDev opened a new pull request, #43459:
URL: https://github.com/apache/superset/pull/43459
### SUMMARY
Saving a dataset with an invalid metric SQL expression correctly blocks the
save, but the error dialog showed only the single character "C" instead of the
backend's validation message, leaving the user with no way to tell what
was wrong.
Root cause: the metric/column expression validator in
`commands/dataset/update.py` raises a marshmallow `ValidationError` with a
`flask_babel.LazyString` message (from `lazy_gettext`). `LazyString` isn't a
`str` subclass, so it fails marshmallow's own
`isinstance(message, (str, bytes))` check in `ValidationError.__init__`,
which means the message is stored bare instead of being wrapped in a list.
The API response ends up as `{"message": {"metrics.0.expression": "Custom
SQL fields cannot be parsed as a single SQL statement."}}` — a plain string
where the frontend expected `string[]`.
`parseErrorJson()` in `getClientErrorObject.ts` assumed every field's value
was always an array and read `Object.values(error.message)[0]?.[0]` — the
"first message of the first field". Against a scalar string, that second
`[0]` indexes into the string itself, returning just its first character.
Fixed `parseErrorJson()` to check `Array.isArray()` before indexing, so it
uses the value directly when it's a string and the first element when it's an
array — mirroring the same defensive pattern already used in
`parsedErrorMessage` (`views/CRUD/hooks.ts`).
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
https://github.com/user-attachments/assets/40a22d01-a48e-4a70-b937-4841f6ab68c7
### TESTING INSTRUCTIONS
1. Edit any dataset → Metrics tab → Add item.
2. Enter a malformed SQL expression, e.g. `SUM(num))`.
3. Save → confirm "save and apply changes".
4. Error dialog now shows the full backend message instead of "C".
Added a regression test in `getClientErrorObject.test.ts` covering a field
message that is a plain string rather than a `string[]`; ran the full
`getClientErrorObject` suite (23 passing) plus `pre-commit run` on the
changed files.
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
- [ ] 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]