feat: Better Errors in SQL Lab (#15432)

* snowflake errors

* added big query

* added to setup error messages, first test

* all big query testing added

* added snowflake test

* added syntax error

* added syntax errors to most used databases
This commit is contained in:
AAfghahi
2021-06-29 19:48:27 -04:00
committed by GitHub
parent 4a394cd6fb
commit 743d9cc928
16 changed files with 412 additions and 4 deletions

View File

@@ -14,12 +14,17 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Optional
import re
from typing import Any, Dict, Optional, Pattern, Tuple
from flask_babel import gettext as __
from sqlalchemy.engine.url import URL
from superset import security_manager
from superset.db_engine_specs.sqlite import SqliteEngineSpec
from superset.errors import SupersetErrorType
SYNTAX_ERROR_REGEX = re.compile('SQLError: near "(?P<server_error>.*?)": syntax error')
class GSheetsEngineSpec(SqliteEngineSpec):
@@ -30,6 +35,17 @@ class GSheetsEngineSpec(SqliteEngineSpec):
allows_joins = False
allows_subqueries = True
custom_errors: Dict[Pattern[str], Tuple[str, SupersetErrorType, Dict[str, Any]]] = {
SYNTAX_ERROR_REGEX: (
__(
'Please check your query for syntax errors near "%(server_error)s". '
"Then, try running your query again."
),
SupersetErrorType.SYNTAX_ERROR,
{},
),
}
@classmethod
def modify_url_for_impersonation(
cls, url: URL, impersonate_user: bool, username: Optional[str]