-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
feat(bigquery): Custom message when Service Account doesnt have the correct Roles and Permissions #21838
Conversation
Codecov Report
@@ Coverage Diff @@
## master #21838 +/- ##
===========================================
- Coverage 66.95% 55.59% -11.36%
===========================================
Files 1807 1807
Lines 69182 69212 +30
Branches 7402 7402
===========================================
- Hits 46319 38479 -7840
- Misses 20952 28822 +7870
Partials 1911 1911
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
# so we try to return the message from the errors instead of using the | ||
# default message | ||
error_list: List[SupersetError] = ex.errors | ||
for error in error_list: |
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.
instead of doing a loop can we just do set check?
if SupersetErrorType.CONNECTION_DATABASE_PERMISSIONS_ERROR in error_list
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.
Hmm error_list
contains a list of SupersetError
, while SupersetErrorType.CONNECTION_DATABASE_PERMISSIONS_ERROR
is just a enum, that comparison won't work. Reducing error_list would also require iterating over the list, so, let me see if there's a more "Pythonic" way of checking without looping. But right now, I don't see how to get to the error_type
for each item in the list without somehow looping over the list.
error.error_type | ||
== SupersetErrorType.CONNECTION_DATABASE_PERMISSIONS_ERROR | ||
): | ||
raise DatabaseConnectionFailedError( |
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.
can we just raise the original DatabaseTestConnectionFailedError
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.
Updated. I am catching the new exception type in the API now along with sending back to the user a dict with the error messages instead of just raw strings.
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.
can you show me the diff between the payload coming back from the API when you send DatabaseConnectionFailedError
vs the original exception?
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.
Before I was raising DatabaseConnectionFailedError
which only has one error in it, so the API response would look like:
{message: '<message_here>'}
while now I'm just throwing the original exception (DatabaseTestConnectionFailed
) which has a list of errors, so the API would respond with a dict like: {[error_type]: [error_message], [error_type_2]: [error_message_2], ...}
which is already a known pattern to the DatabaseModal
for error displaying.
So basically after the change based on the input you gave me, I'm doing the latter.
For example:
Before when throwing a DatabaseConnectionFailedError
the API would respond:
422
{
message: 'Unable to connect. Verify that the following roles are set on the service account: "BigQuery Data Viewer", "BigQuery Metadata Viewer", "BigQuery Job User" and the following permissions are set "bigquery.readsessions.create", "bigquery.readsessions.getData"'
}
And now throwing the original DatabaseTestConnectionFailed
it looks like:
422
{
CONNECTION_DATABASE_PERMISSIONS_ERROR: 'Unable to connect. Verify that the following roles are set on the service account: "BigQuery Data Viewer", "BigQuery Metadata Viewer", "BigQuery Job User" and the following permissions are set "bigquery.readsessions.create", "bigquery.readsessions.getData"',
...
<other_errors_here>
}
4dfe6d0
to
99f166b
Compare
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.
Able to see the custom msg for error msg. LGTM
99f166b
to
3909223
Compare
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0], | ||
) | ||
# So we can show the original message | ||
raise 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.
Original message
-> Custom message after extracting the error.
Otherwise the DatabaseConnectionFailedError
would have the default Connection failed ...
message caught from below.
c932d96
to
38a9003
Compare
38a9003
to
5a11829
Compare
@@ -145,7 +152,7 @@ def ping(engine: Engine) -> bool: | |||
) | |||
# check for custom errors (wrong username, wrong password, etc) | |||
errors = database.db_engine_spec.extract_errors(ex, context) | |||
raise DatabaseTestConnectionFailedError(errors) from ex | |||
raise SupersetErrorsException(errors) from 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.
@Antonio-RiveroMartnez I'm looking into some 500 errors for test connections, and I saw this change. What would happen if I were to change this back to raise the DatabaseTestConnectionFailedError
which is a 422? Would it break anything from this PR? I checked through the implementation and it looks like it should still catch the SupersetErrorsExceptions because it is the base class, but I wanted to see if I might be missing anything here.
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.
Hey @eschutho, the problem of doing that is that we would lost the original message
and instead the message from DatabaseTestConnectionFailedError would be used (Connection failed, please check your connection settings
) and not the custom message with roles after parsing the original message.
SUMMARY
BigQuery
is now returning the project name twice in the error message when connecting, which breaks the Regex in thecustom_errors
dictionary, so we need to adjust it in order to stop displaying the general connection failed message. Also, we are updating the message displayed to users and the tests.Additionally, in order to actually being able to catch the right error, we are raising the exceptions with their original message instead of the default one, otherwise the exception handler will ignore it and display the default message.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:
After:
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION