Skip to content

Commit

Permalink
fix: better logic to extract errors on databricks (#22792)
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Jan 20, 2023
1 parent 92cdb8c commit d091a68
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
13 changes: 8 additions & 5 deletions superset/db_engine_specs/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,15 @@ def extract_errors(
raw_message = cls._extract_error_message(ex)

context = context or {}
# access_token isn't currently parseable from the
# databricks error response, but adding it in here
# for reference if their error message changes
context = {
"host": context["hostname"],
"access_token": context["password"],
"port": context["port"],
"username": context["username"],
"database": context["database"],
"host": context.get("hostname"),
"access_token": context.get("password"),
"port": context.get("port"),
"username": context.get("username"),
"database": context.get("database"),
}
for regex, (message, error_type, extra) in cls.custom_errors.items():
match = regex.search(raw_message)
Expand Down
56 changes: 56 additions & 0 deletions tests/unit_tests/db_engine_specs/test_databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

import json

import pytest
from pytest_mock import MockerFixture

from superset.db_engine_specs.databricks import DatabricksNativeEngineSpec
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
from superset.utils.core import GenericDataType


Expand Down Expand Up @@ -197,3 +200,56 @@ def test_get_extra_params(mocker: MockerFixture) -> None:
}
}
}


def test_extract_errors() -> None:
"""
Test that custom error messages are extracted correctly.
"""

msg = ": mismatched input 'fromm'. Expecting: "
result = DatabricksNativeEngineSpec.extract_errors(Exception(msg))

assert result == [
SupersetError(
message=": mismatched input 'fromm'. Expecting: ",
error_type=SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
level=ErrorLevel.ERROR,
extra={
"engine_name": "Databricks",
"issue_codes": [
{
"code": 1002,
"message": "Issue 1002 - The database returned an unexpected error.",
}
],
},
)
]


def test_extract_errors_with_context() -> None:
"""
Test that custom error messages are extracted correctly with context.
"""

msg = ": mismatched input 'fromm'. Expecting: "
context = {"hostname": "foo"}
result = DatabricksNativeEngineSpec.extract_errors(Exception(msg), context)

assert result == [
SupersetError(
message=": mismatched input 'fromm'. Expecting: ",
error_type=SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
level=ErrorLevel.ERROR,
extra={
"engine_name": "Databricks",
"issue_codes": [
{
"code": 1002,
"message": "Issue 1002 - The database returned an unexpected error.",
}
],
},
)
]

0 comments on commit d091a68

Please sign in to comment.