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

chore: add logs to db test connection and post failures #13223

Closed
wants to merge 19 commits into from
Closed
2 changes: 2 additions & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def post(self) -> Response:
except DatabaseInvalidError as ex:
return self.response_422(message=ex.normalized_messages())
except DatabaseConnectionFailedError as ex:
logger.warning("Database connection failed: %s", item["sqlalchemy_uri"])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log will be masked uri

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that item["sqlalchemy_uri" is only updated with the masked version if line 236 is reached - if CreateDatabaseCommand(...).run() fails, as we can expect if this code is reached, then I believe there's a good chance that the full sqlalchemy_uri will be logged.

While the masked URI is better than the full URI, it still exposes username and additional connection information that it might be better not to have in logs.

return self.response_422(message=str(ex))
except DatabaseCreateFailedError as ex:
logger.error(
Expand Down Expand Up @@ -607,6 +608,7 @@ def test_connection( # pylint: disable=too-many-return-statements
TestConnectionDatabaseCommand(g.user, item).run()
return self.response(200, message="OK")
except DatabaseTestConnectionFailedError as ex:
logger.warning(ex)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this log will read out the following:
WARNING:superset.databases.api:Could not load database driver: mssql+pymssql

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is one possible error message - others are not so innocuous and include username and password information. We've seen that with a few different database engines.

return self.response_422(message=str(ex))

@expose("/<int:pk>/related_objects/", methods=["GET"])
Expand Down