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

fix: don't close cursor before closing connection #12821

Merged
merged 1 commit into from Jan 28, 2021

Conversation

betodealmeida
Copy link
Member

@betodealmeida betodealmeida commented Jan 28, 2021

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 closing(engine.raw_connection()) as conn:
    with closing(conn.cursor()) as cursor:
        cursor.execute(sql)

With:

with closing(engine.raw_connection()) as conn:
    cursor = conn.cursor()
    cursor.execute(sql)

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

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@codecov-io
Copy link

Codecov Report

Merging #12821 (eb3fb37) into master (365770e) will decrease coverage by 3.45%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12821      +/-   ##
==========================================
- Coverage   66.84%   63.38%   -3.46%     
==========================================
  Files        1022      488     -534     
  Lines       50070    30143   -19927     
  Branches     4914        0    -4914     
==========================================
- Hits        33468    19106   -14362     
+ Misses      16478    11037    -5441     
+ Partials      124        0     -124     
Flag Coverage Δ
cypress ?
javascript ?
python 63.38% <89.47%> (-0.45%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/sql_lab.py 80.18% <89.47%> (ø)
superset/utils/celery.py 86.20% <0.00%> (-13.80%) ⬇️
superset/databases/commands/create.py 83.67% <0.00%> (-8.17%) ⬇️
superset/databases/commands/update.py 85.71% <0.00%> (-8.17%) ⬇️
superset/connectors/sqla/models.py 84.31% <0.00%> (-6.28%) ⬇️
superset/db_engine_specs/sqlite.py 90.62% <0.00%> (-6.25%) ⬇️
superset/databases/commands/test_connection.py 84.78% <0.00%> (-4.35%) ⬇️
superset/models/core.py 85.59% <0.00%> (-2.99%) ⬇️
superset/databases/api.py 89.49% <0.00%> (-2.53%) ⬇️
superset/views/core.py 72.97% <0.00%> (-2.45%) ⬇️
... and 546 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 365770e...eb3fb37. Read the comment docs.

@betodealmeida betodealmeida merged commit 8bdd01e into apache:master Jan 28, 2021
henryyeh pushed a commit to preset-io/superset that referenced this pull request Jan 28, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants