From e78afdc051d19d5c94b3f33c42f1df2809d54288 Mon Sep 17 00:00:00 2001 From: AAfghahi <48933336+AAfghahi@users.noreply.github.com> Date: Fri, 30 Apr 2021 18:15:37 -0400 Subject: [PATCH] fix: fixing mysql error message (#14416) * fixing mysql error message * Update tests/db_engine_specs/mysql_tests.py Co-authored-by: Beto Dealmeida * Update tests/db_engine_specs/mysql_tests.py Co-authored-by: Beto Dealmeida * Update tests/db_engine_specs/mysql_tests.py Co-authored-by: Beto Dealmeida * Update superset/db_engine_specs/mysql.py Co-authored-by: Beto Dealmeida * fixed broken test * changed error type Co-authored-by: Beto Dealmeida --- superset/db_engine_specs/mysql.py | 8 ++++---- superset/db_engine_specs/postgres.py | 5 +++++ tests/db_engine_specs/mysql_tests.py | 10 +++++----- tests/db_engine_specs/postgres_tests.py | 25 +++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/superset/db_engine_specs/mysql.py b/superset/db_engine_specs/mysql.py index b72b006c601c0..a5d4a16052dd5 100644 --- a/superset/db_engine_specs/mysql.py +++ b/superset/db_engine_specs/mysql.py @@ -42,15 +42,15 @@ # Regular expressions to catch custom errors CONNECTION_ACCESS_DENIED_REGEX = re.compile( - "Access denied for user '(?P.*?)'@'(?P.*?)'. " + "Access denied for user '(?P.*?)'@'(?P.*?)'" ) CONNECTION_INVALID_HOSTNAME_REGEX = re.compile( - "Unknown MySQL server host '(?P.*?)'." + "Unknown MySQL server host '(?P.*?)'" ) CONNECTION_HOST_DOWN_REGEX = re.compile( - "Can't connect to MySQL server on '(?P.*?)'." + "Can't connect to MySQL server on '(?P.*?)'" ) -CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile("Unknown database '(?P.*?)'.") +CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile("Unknown database '(?P.*?)'") class MySQLEngineSpec(BaseEngineSpec): diff --git a/superset/db_engine_specs/postgres.py b/superset/db_engine_specs/postgres.py index c2e6776a54c11..abca36d5c04f3 100644 --- a/superset/db_engine_specs/postgres.py +++ b/superset/db_engine_specs/postgres.py @@ -62,6 +62,7 @@ class FixedOffsetTimezone(_FixedOffset): CONNECTION_INVALID_PASSWORD_REGEX = re.compile( 'password authentication failed for user "(?P.*?)"' ) +CONNECTION_INVALID_PASSWORD_NEEDED_REGEX = re.compile("no password supplied") CONNECTION_INVALID_HOSTNAME_REGEX = re.compile( 'could not translate host name "(?P.*?)" to address: ' "nodename nor servname provided, or not known" @@ -108,6 +109,10 @@ class PostgresBaseEngineSpec(BaseEngineSpec): __('The password provided for username "%(username)s" is incorrect.'), SupersetErrorType.CONNECTION_INVALID_PASSWORD_ERROR, ), + CONNECTION_INVALID_PASSWORD_NEEDED_REGEX: ( + __("Please re-enter the password."), + SupersetErrorType.CONNECTION_ACCESS_DENIED_ERROR, + ), CONNECTION_INVALID_HOSTNAME_REGEX: ( __('The hostname "%(hostname)s" cannot be resolved.'), SupersetErrorType.CONNECTION_INVALID_HOSTNAME_ERROR, diff --git a/tests/db_engine_specs/mysql_tests.py b/tests/db_engine_specs/mysql_tests.py index b40fd281bbeef..fb2d44aaaad03 100644 --- a/tests/db_engine_specs/mysql_tests.py +++ b/tests/db_engine_specs/mysql_tests.py @@ -110,7 +110,7 @@ def test_extract_errors(self): """ Test that custom error messages are extracted correctly. """ - msg = "mysql: Access denied for user 'test'@'testuser.com'. " + msg = "mysql: Access denied for user 'test'@'testuser.com'" result = MySQLEngineSpec.extract_errors(Exception(msg)) assert result == [ SupersetError( @@ -135,7 +135,7 @@ def test_extract_errors(self): ) ] - msg = "mysql: Unknown MySQL server host 'badhostname.com'. " + msg = "mysql: Unknown MySQL server host 'badhostname.com'" result = MySQLEngineSpec.extract_errors(Exception(msg)) assert result == [ SupersetError( @@ -155,7 +155,7 @@ def test_extract_errors(self): ) ] - msg = "mysql: Can't connect to MySQL server on 'badconnection.com'." + msg = "mysql: Can't connect to MySQL server on 'badconnection.com'" result = MySQLEngineSpec.extract_errors(Exception(msg)) assert result == [ SupersetError( @@ -176,7 +176,7 @@ def test_extract_errors(self): ) ] - msg = "mysql: Can't connect to MySQL server on '93.184.216.34'." + msg = "mysql: Can't connect to MySQL server on '93.184.216.34'" result = MySQLEngineSpec.extract_errors(Exception(msg)) assert result == [ SupersetError( @@ -196,7 +196,7 @@ def test_extract_errors(self): ) ] - msg = "mysql: Unknown database 'badDB'." + msg = "mysql: Unknown database 'badDB'" result = MySQLEngineSpec.extract_errors(Exception(msg)) assert result == [ SupersetError( diff --git a/tests/db_engine_specs/postgres_tests.py b/tests/db_engine_specs/postgres_tests.py index 6c8b8e5840158..1dc044eee21f5 100644 --- a/tests/db_engine_specs/postgres_tests.py +++ b/tests/db_engine_specs/postgres_tests.py @@ -389,6 +389,31 @@ def test_extract_errors(self): ) ] + msg = "no password supplied" + result = PostgresEngineSpec.extract_errors(Exception(msg)) + assert result == [ + SupersetError( + error_type=SupersetErrorType.CONNECTION_ACCESS_DENIED_ERROR, + message="Please re-enter the password.", + level=ErrorLevel.ERROR, + extra={ + "engine_name": "PostgreSQL", + "issue_codes": [ + { + "code": 1014, + "message": "Issue 1014 - Either the" + " username or the password is wrong.", + }, + { + "code": 1015, + "message": "Issue 1015 - Either the database is " + "spelled incorrectly or does not exist.", + }, + ], + }, + ) + ] + def test_base_parameters_mixin(): parameters = {