-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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(imports): Error when importing charts / dashboards with missing DB credentials #30503
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #30503 +/- ##
===========================================
+ Coverage 60.48% 83.92% +23.43%
===========================================
Files 1931 533 -1398
Lines 76236 38538 -37698
Branches 8568 0 -8568
===========================================
- Hits 46114 32344 -13770
+ Misses 28017 6194 -21823
+ Partials 2105 0 -2105
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
||
try: | ||
add_permissions(database, ssh_tunnel) | ||
except SupersetDBAPIConnectionError as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might occur by other connection errors and not only the credentials one, right? So we would be affecting other engines too and not just BigQuery. Could we instead use the custom_errors in the db_engine_spec and map the credentials one to something we could target individually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, this would affect other DBs. While this bug emerged in the specific case of BigQuery, there are other DBs that may error as well when trying to set up catalogs on import if it's unable to connect. Regardless of the cause of the connection error, be it creds or otherwise, we still shouldn't be blocking the import because it can't connect when looking to add catalogs, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the credentials error for BigQuery is being mapped to the SupersetDBAPIConnectionError
superset/superset/db_engine_specs/bigquery.py
Line 605 in 68c9a81
return {DefaultCredentialsError: SupersetDBAPIConnectionError} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd only allow the exception if the database is configured for OAuth2. But even more ideally we'd do what the TODO says, and use CreateDatabaseCommand
for the imports, since the command already handles edge cases like this. So I think this is OK for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
@@ -738,7 +738,7 @@ def _get_fields(cls, cols: list[ResultSetColumnType]) -> list[Any]: | |||
@classmethod | |||
def parse_error_exception(cls, exception: Exception) -> Exception: | |||
try: | |||
return Exception(str(exception).splitlines()[0].strip()) | |||
return type(exception)(str(exception).splitlines()[0].strip()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method parse_error_exception
is very confusing... I think it's really unlikely that str(exception).splitlines()[0].strip()
will raise an exception — it only happens if str(exception)
is ''
or if there's some shennanigans in the exception class __str__
method.
I think what the method is trying to do is limit the exception message to the first line, but there are better ways to do that. But it's OK, we can refactor later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I was running into was when a mapped SupersetDBAPIError
was being passed into this method, it would then be remapped to a base class Exception
type with the message preserved. I was trying to preserve the Exception type as well as the message
|
||
try: | ||
add_permissions(database, ssh_tunnel) | ||
except SupersetDBAPIConnectionError as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd only allow the exception if the database is configured for OAuth2. But even more ideally we'd do what the TODO says, and use CreateDatabaseCommand
for the imports, since the command already handles edge cases like this. So I think this is OK for now.
SUMMARY
When importing charts, dashboards, and databases, certain databases (BigQuery) require credentials to be entered into the encrypted extra field for authorization. When importing this type of database, or any chart or dashboard that relies on this type of database, the db creation will fail generating an import failed error.
This fix implements a try except block to catch connection errors when attempting to populate db catalogs when importing a db. It prevents bigquery exceptions from being remapped to generic Exception types.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:
https://www.loom.com/share/ca5efd11ba004c19aea9c83484bdab47?sid=6be35dfc-42e1-45b2-81dd-0a8df1d41dd6
After:
https://www.loom.com/share/a9cc247ddb434ee198f81503514f6776?sid=93c7481f-9ace-4def-9862-6567ecf2f32b
TESTING INSTRUCTIONS
Export a bigquery database or a chart/dashboard linked to a bigquery db.
Delete the underlying db
Attempt to import the db, chart, or dashboard.
The import should be successful, even though the db does not have auth creds
ADDITIONAL INFORMATION