Skip to content

Commit

Permalink
fix: fixing mysql error message (#14416)
Browse files Browse the repository at this point in the history
* fixing mysql error message

* Update tests/db_engine_specs/mysql_tests.py

Co-authored-by: Beto Dealmeida <[email protected]>

* Update tests/db_engine_specs/mysql_tests.py

Co-authored-by: Beto Dealmeida <[email protected]>

* Update tests/db_engine_specs/mysql_tests.py

Co-authored-by: Beto Dealmeida <[email protected]>

* Update superset/db_engine_specs/mysql.py

Co-authored-by: Beto Dealmeida <[email protected]>

* fixed broken test

* changed error type

Co-authored-by: Beto Dealmeida <[email protected]>
  • Loading branch information
AAfghahi and betodealmeida authored Apr 30, 2021
1 parent e507508 commit 7466595
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
8 changes: 4 additions & 4 deletions superset/db_engine_specs/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@

# Regular expressions to catch custom errors
CONNECTION_ACCESS_DENIED_REGEX = re.compile(
"Access denied for user '(?P<username>.*?)'@'(?P<hostname>.*?)'. "
"Access denied for user '(?P<username>.*?)'@'(?P<hostname>.*?)'"
)
CONNECTION_INVALID_HOSTNAME_REGEX = re.compile(
"Unknown MySQL server host '(?P<hostname>.*?)'."
"Unknown MySQL server host '(?P<hostname>.*?)'"
)
CONNECTION_HOST_DOWN_REGEX = re.compile(
"Can't connect to MySQL server on '(?P<hostname>.*?)'."
"Can't connect to MySQL server on '(?P<hostname>.*?)'"
)
CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile("Unknown database '(?P<database>.*?)'.")
CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile("Unknown database '(?P<database>.*?)'")


class MySQLEngineSpec(BaseEngineSpec):
Expand Down
5 changes: 5 additions & 0 deletions superset/db_engine_specs/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class FixedOffsetTimezone(_FixedOffset):
CONNECTION_INVALID_PASSWORD_REGEX = re.compile(
'password authentication failed for user "(?P<username>.*?)"'
)
CONNECTION_INVALID_PASSWORD_NEEDED_REGEX = re.compile("no password supplied")
CONNECTION_INVALID_HOSTNAME_REGEX = re.compile(
'could not translate host name "(?P<hostname>.*?)" to address: '
"nodename nor servname provided, or not known"
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions tests/db_engine_specs/mysql_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
25 changes: 25 additions & 0 deletions tests/db_engine_specs/postgres_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 7466595

Please sign in to comment.