msyavuz commented on code in PR #43459:
URL: https://github.com/apache/superset/pull/43459#discussion_r3845166496


##########
superset-frontend/packages/superset-ui-core/src/query/getClientErrorObject.ts:
##########
@@ -126,13 +126,17 @@ export function parseErrorJson(responseJson: JsonObject): 
ClientErrorObject {
     error.error = error.description = error.errors[0].message;
     error.link = error.errors[0]?.extra?.link;
   }
-  // Marshmallow field validation returns the error message in the format
-  // of { message: { field1: [msg1, msg2], field2: [msg], } }
+  // Marshmallow field validation returns { field1: [msg1, msg2], ... },
+  // but some validators attach a bare string instead of a list.

Review Comment:
   Root cause looks like `_validate_expressions` passing a bare `lazy_gettext` 
message while the other dataset `ValidationError`s wrap it (`[_("...")]` in 
`commands/dataset/exceptions.py`) — worth fixing at 
`commands/dataset/update.py:386` too, so the 422 keeps its documented `{field: 
[msg]}` shape for non-frontend clients?



##########
superset-frontend/packages/superset-ui-core/src/query/getClientErrorObject.ts:
##########
@@ -126,13 +126,17 @@ export function parseErrorJson(responseJson: JsonObject): 
ClientErrorObject {
     error.error = error.description = error.errors[0].message;
     error.link = error.errors[0]?.extra?.link;
   }
-  // Marshmallow field validation returns the error message in the format
-  // of { message: { field1: [msg1, msg2], field2: [msg], } }
+  // Marshmallow field validation returns { field1: [msg1, msg2], ... },
+  // but some validators attach a bare string instead of a list.
   if (!error.error && error.message) {
     if (typeof error.message === 'object') {
+      const firstFieldMessage = Object.values(
+        error.message as Record<string, string[] | string>,

Review Comment:
   Nested marshmallow errors still hit this non-array branch and assign an 
object to `error.error` — a bad report recipient gives `{"recipients": {"0": 
{"type": [...]}}}`. In scope here, or deliberately left alone?



-- 
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