From 4ba17092fa7bc1cf3317a5ce127e0c4ece55c3a4 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Fri, 23 Jul 2021 15:19:30 -0700 Subject: [PATCH] fix: Ensure SupersetError.extra is always a dict (#15848) Co-authored-by: John Bodley --- .../components/ErrorMessage/DatabaseErrorMessage.tsx | 11 +++++++---- superset/exceptions.py | 1 - superset/views/base.py | 2 -- tests/integration_tests/databases/commands_tests.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/superset-frontend/src/components/ErrorMessage/DatabaseErrorMessage.tsx b/superset-frontend/src/components/ErrorMessage/DatabaseErrorMessage.tsx index 5798f3b41..9a131f1e2 100644 --- a/superset-frontend/src/components/ErrorMessage/DatabaseErrorMessage.tsx +++ b/superset-frontend/src/components/ErrorMessage/DatabaseErrorMessage.tsx @@ -41,7 +41,7 @@ function DatabaseErrorMessage({ const isVisualization = ['dashboard', 'explore'].includes(source); - const body = ( + const body = extra && ( <>

{t('This may be triggered by:')} @@ -75,13 +75,16 @@ function DatabaseErrorMessage({ ); - const copyText = `${message} + const copyText = + extra && extra.issue_codes + ? `${message} ${t('This may be triggered by:')} -${extra.issue_codes.map(issueCode => issueCode.message).join('\n')}`; +${extra.issue_codes.map(issueCode => issueCode.message).join('\n')}` + : message; return ( FlaskResponse: message=utils.error_msg_from_exception(ex), error_type=SupersetErrorType.GENERIC_BACKEND_ERROR, level=ErrorLevel.ERROR, - extra={}, ), ], status=ex.code or 500, @@ -449,7 +448,6 @@ def show_unexpected_exception(ex: Exception) -> FlaskResponse: message=utils.error_msg_from_exception(ex), error_type=SupersetErrorType.GENERIC_BACKEND_ERROR, level=ErrorLevel.ERROR, - extra={}, ), ], ) diff --git a/tests/integration_tests/databases/commands_tests.py b/tests/integration_tests/databases/commands_tests.py index 0fe6d6bc8..7d762b10f 100644 --- a/tests/integration_tests/databases/commands_tests.py +++ b/tests/integration_tests/databases/commands_tests.py @@ -587,7 +587,7 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase): connection exc is raised""" database = get_example_database() mock_get_sqla_engine.side_effect = SupersetSecurityException( - SupersetError(error_type=500, message="test", level="info", extra={}) + SupersetError(error_type=500, message="test", level="info") ) db_uri = database.sqlalchemy_uri_decrypted json_payload = {"sqlalchemy_uri": db_uri}