Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better logic to extract errors on databricks #22792

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.",
}
],
},
)
]