fix: don't close cursor before closing connection #12821
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
When running a statement in SQL Lab, after the query is finished we first close the cursor and then close the connection (using the
closing
context manager). This raises an exception in BigQuery due to a bug (googleapis/python-bigquery#497), and even though the exception is captured and the code works it pollutes the logs, creating an error entry for every statement executed.I created a PR fixing the bug upstream (googleapis/python-bigquery#498), but in the meantime we can prevent this from happening by simply not closing the cursor explicitly. This is possible because closing a connection will close all its cursors (the exception in BigQuery happens because it tries to close the already closed cursor).
This means we can replace this:
With:
With this change, BigQuery will no longer try to close the closed cursor, keeping the logs clean.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TEST PLAN
Ran a simple query in BigQuery, and verified that the error message no longer shows up in the logs.
ADDITIONAL INFORMATION