You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2022/07/27 18:41:24 UTC

[superset] branch master updated: fix(sql lab): Syntax errors should return with 422 status (#20491)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 383313b105 fix(sql lab): Syntax errors should return with 422 status (#20491)
383313b105 is described below

commit 383313b105b0e82bea0f38cc971630eded5affe0
Author: Diego Medina <di...@gmail.com>
AuthorDate: Wed Jul 27 15:41:17 2022 -0300

    fix(sql lab): Syntax errors should return with 422 status (#20491)
    
    * fix(sql lab): Syntax errors should return with 422 status
    
    * refactor
---
 superset/exceptions.py     |  8 ++++++++
 superset/sqllab/command.py | 25 ++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/superset/exceptions.py b/superset/exceptions.py
index 07bedfa2db..153d7439eb 100644
--- a/superset/exceptions.py
+++ b/superset/exceptions.py
@@ -115,6 +115,14 @@ class SupersetErrorsException(SupersetException):
             self.status = status
 
 
+class SupersetSyntaxErrorException(SupersetErrorsException):
+    status = 422
+    error_type = SupersetErrorType.SYNTAX_ERROR
+
+    def __init__(self, errors: List[SupersetError]) -> None:
+        super().__init__(errors)
+
+
 class SupersetTimeoutException(SupersetErrorFromParamsException):
     status = 408
 
diff --git a/superset/sqllab/command.py b/superset/sqllab/command.py
index ce41eb6de2..0aeab754ca 100644
--- a/superset/sqllab/command.py
+++ b/superset/sqllab/command.py
@@ -25,8 +25,13 @@ from flask_babel import gettext as __
 from superset.commands.base import BaseCommand
 from superset.common.db_query_status import QueryStatus
 from superset.dao.exceptions import DAOCreateFailedError
-from superset.errors import SupersetErrorType
-from superset.exceptions import SupersetErrorsException, SupersetGenericErrorException
+from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
+from superset.exceptions import (
+    SupersetErrorsException,
+    SupersetException,
+    SupersetGenericErrorException,
+    SupersetSyntaxErrorException,
+)
 from superset.models.core import Database
 from superset.models.sql_lab import Query
 from superset.sqllab.command_status import SqlJsonExecutionStatus
@@ -110,7 +115,21 @@ class ExecuteSqlCommand(BaseCommand):
                 "status": status,
                 "payload": self._execution_context_convertor.serialize_payload(),
             }
-        except (SqlLabException, SupersetErrorsException) as ex:
+        except SupersetErrorsException as ex:
+            if all(ex.error_type == SupersetErrorType.SYNTAX_ERROR for ex in ex.errors):
+                raise SupersetSyntaxErrorException(ex.errors) from ex
+            raise ex
+        except SupersetException as ex:
+            if ex.error_type == SupersetErrorType.SYNTAX_ERROR:
+                raise SupersetSyntaxErrorException(
+                    [
+                        SupersetError(
+                            message=ex.message,
+                            error_type=ex.error_type,
+                            level=ErrorLevel.ERROR,
+                        )
+                    ]
+                ) from ex
             raise ex
         except Exception as ex:
             raise SqlLabException(self._execution_context, exception=ex) from ex