sadpandajoe commented on code in PR #43666:
URL: https://github.com/apache/superset/pull/43666#discussion_r4129232687


##########
superset/commands/dashboard/update.py:
##########
@@ -168,6 +169,24 @@ def validate(self) -> None:
         except ValidationError as ex:
             exceptions.append(ex)
 
+        # A dashboard PUT resends the full object on every save, so only
+        # validate css when it's actually changing -- otherwise a dashboard
+        # whose existing css predates this check (or was imported without
+        # going through it) becomes uneditable for unrelated changes like a
+        # rename or a chart move.
+        if "css" in self._properties:
+            new_css = self._properties["css"]
+            if new_css != self._model.css:
+                try:
+                    validate_css(new_css)
+                except ValidationError as ex:
+                    # Re-key under "css" -- validate_css() raises with the
+                    # default "_schema" field_name, since it's also used as
+                    # a marshmallow field validator elsewhere, where
+                    # marshmallow assigns the field name itself regardless
+                    # of what's set here.
+                    exceptions.append(ValidationError(ex.messages, 
field_name="css"))

Review Comment:
   This moves a rejected `css` value from the schema-level `ValidationError` 
path (`DashboardPutSchema.load()` failing, caught in the API view and returned 
as HTTP 400) to this command-level `DashboardInvalidError`, which the same view 
maps to HTTP 422 instead. A client or integration that branches on 400 vs. 422 
for this PUT endpoint now gets a different status code for the same rejected 
`css` value than it did before this PR. Is that status change intentional, or 
should a rejected css value keep returning 400?



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