Skip to content

Commit cc4dde2

Browse files
committed
Apply PR feedback
1 parent 1f8cf7a commit cc4dde2

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

superset/db_engine_specs/base.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,20 @@ def _extract_error_message(cls, ex: Exception) -> str:
13261326
"""Extract error message for queries"""
13271327
return utils.error_msg_from_exception(ex)
13281328

1329+
@classmethod
1330+
def get_database_custom_errors(
1331+
cls, database_name: str | None
1332+
) -> dict[Any, tuple[str, SupersetErrorType, dict[str, Any]]]:
1333+
config_custom_errors = app.config.get("CUSTOM_DATABASE_ERRORS", {})
1334+
if not isinstance(config_custom_errors, dict):
1335+
return {}
1336+
1337+
if database_name and database_name in config_custom_errors:
1338+
database_errors = config_custom_errors[database_name]
1339+
if isinstance(database_errors, dict):
1340+
return database_errors
1341+
return {}
1342+
13291343
@classmethod
13301344
def extract_errors(
13311345
cls,
@@ -1336,21 +1350,7 @@ def extract_errors(
13361350
raw_message = cls._extract_error_message(ex)
13371351

13381352
context = context or {}
1339-
1340-
config_custom_errors = app.config.get("CUSTOM_DATABASE_ERRORS", {})
1341-
1342-
if not isinstance(config_custom_errors, dict):
1343-
config_custom_errors = {}
1344-
1345-
db_engine_custom_errors = {}
1346-
1347-
if database_name and database_name in config_custom_errors:
1348-
database_errors = config_custom_errors[database_name]
1349-
if isinstance(database_errors, dict):
1350-
db_engine_custom_errors.update(database_errors)
1351-
1352-
if not isinstance(db_engine_custom_errors, dict):
1353-
db_engine_custom_errors = {}
1353+
db_engine_custom_errors = cls.get_database_custom_errors(database_name)
13541354

13551355
for regex, (message, error_type, extra) in [
13561356
*db_engine_custom_errors.items(),

superset/db_engine_specs/databricks.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
from apispec import APISpec
2323
from apispec.ext.marshmallow import MarshmallowPlugin
24-
from flask import current_app as app
2524
from flask_babel import gettext as __
2625
from marshmallow import fields, Schema
2726
from marshmallow.validate import Range
@@ -306,24 +305,14 @@ def extract_errors(
306305

307306
context = context or {}
308307

309-
config_custom_errors = app.config.get("CUSTOM_DATABASE_ERRORS", {})
310308
# access_token isn't currently parseable from the
311309
# databricks error response, but adding it in here
312310
# for reference if their error message changes
313311

314312
for key, value in cls.context_key_mapping.items():
315313
context[key] = context.get(value)
316314

317-
if not isinstance(config_custom_errors, dict):
318-
config_custom_errors = {}
319-
320-
db_engine_custom_errors = {}
321-
322-
if database_name and database_name in config_custom_errors:
323-
database_errors = config_custom_errors[database_name]
324-
if isinstance(database_errors, dict):
325-
db_engine_custom_errors.update(database_errors)
326-
315+
db_engine_custom_errors = cls.get_database_custom_errors(database_name)
327316
if not isinstance(db_engine_custom_errors, dict):
328317
db_engine_custom_errors = {}
329318

0 commit comments

Comments
 (0)