fix(#13378): Ensure g.user is set for impersonation #13878
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
This fixes #13378 by ensuring that Flask's global object
g
contains auser
object set to the user who initiated the request when queries are executing asynchronously. There is currently some deeply buried code that expects this when constructing the query. This is not a particularly robust fix, so if anyone has any suggestions I'd be very interested in hearing them. Ideally, we'd have a way to explicitly pass the username to where it's needed for impersonation configuration (like SQL lab does), but this would require a substantial amount of changes as far as I can tell. Even if refactoring that is the goal, I think we should get this out to unblock folks first.TEST PLAN
This is difficult to test well, so the unit tests were updated to ensure a function is called that I manually tested. This is not a great test, and I almost omitted it altogether, but ended up including it. Let me know if you have suggestions.
Additionally, I would like to test this end-to-end but I don't have that environment setup yet. I'm going to work to get this set up. In the meantime, @juneauwang and @gorcurek if you're able to pull this branch down and test it, that would be lovely.
ADDITIONAL INFORMATION