fix: show custom errors in SQL Lab (#14959)

* fix: show custom errors in SQL Lab

* Fix lint

* Fix test

* Update superset/views/base.py

Co-authored-by: ʈᵃᵢ <tai@apache.org>

* Fix lint

* Debug failing test

* Remove print()

* Debug flaky tests

* Fix test

Co-authored-by: ʈᵃᵢ <tai@apache.org>
This commit is contained in:
Beto Dealmeida
2021-06-10 15:20:31 -07:00
committed by GitHub
parent f8b270d419
commit cc2b4fe3f4
5 changed files with 35 additions and 4 deletions

View File

@@ -80,6 +80,10 @@ CONNECTION_HOST_DOWN_REGEX = re.compile(
CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile(
'database "(?P<database>.*?)" does not exist'
)
COLUMN_DOES_NOT_EXIST_REGEX = re.compile(
r'postgresql error: column "(?P<column_name>.+?)" '
r"does not exist\s+LINE (?P<location>\d+?)"
)
class PostgresBaseEngineSpec(BaseEngineSpec):
@@ -100,7 +104,7 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
"P1Y": "DATE_TRUNC('year', {col})",
}
custom_errors = {
custom_errors: Dict[Pattern[str], Tuple[str, SupersetErrorType, Dict[str, Any]]] = {
CONNECTION_INVALID_USERNAME_REGEX: (
__('The username "%(username)s" does not exist.'),
SupersetErrorType.CONNECTION_INVALID_USERNAME_ERROR,
@@ -139,6 +143,14 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
SupersetErrorType.CONNECTION_UNKNOWN_DATABASE_ERROR,
{"invalid": ["database"]},
),
COLUMN_DOES_NOT_EXIST_REGEX: (
__(
'We can\'t seem to resolve the column "%(column_name)s" at '
"line %(location)s.",
),
SupersetErrorType.COLUMN_DOES_NOT_EXIST_ERROR,
{},
),
}
@classmethod