EnxDev commented on code in PR #43334:
URL: https://github.com/apache/superset/pull/43334#discussion_r3852276845


##########
superset/commands/dataset/create.py:
##########
@@ -50,7 +54,25 @@ def run(self) -> Model:
         self.validate()
 
         dataset = DatasetDAO.create(attributes=self._properties)
-        dataset.fetch_metadata()
+        try:
+            dataset.fetch_metadata()
+        except SupersetException as ex:
+            # Not a SQLAlchemyError, so ``on_error`` re-raises it untouched and
+            # it escapes to FAB's ``@safe`` as an opaque 500 "Fatal error".
+            # Deliberately covers the 403 ``SupersetSecurityException`` raised
+            # for mutation/multi-statement SQL too: ``validate()`` already
+            # reports that class of rejection as a 422 on ``sql`` via
+            # ``DatasetDataAccessIsNotAllowed``.
+            raise DatasetInvalidError(
+                exceptions=[
+                    ValidationError(
+                        # ``lazy_gettext`` messages aren't ``str``, so
+                        # marshmallow won't wrap them into a list on its own.
+                        [str(ex.message)],

Review Comment:
   Fixed at the source. The ugly text was actually built upstream in 
`connectors/sqla/utils.py's ` `get_virtual_table_metadata()`, which used 
str(ex) on a `SupersetSyntaxErrorException` (stringifying the raw SupersetError 
list, enum reprs included) before wrapping it into 
SupersetGenericDBErrorException. 
   Changed it to join `ex.errors[*].message` instead, giving a clean string. 
Added test_get_virtual_table_metadata_template_error_message_is_clean to lock 
in the clean output.



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