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

Add try/catch to cursor.fetchall() #7504

Closed
wants to merge 2 commits into from
Closed

Conversation

leiwan5
Copy link

@leiwan5 leiwan5 commented May 14, 2019

I use SQL_QUERY_MUTATOR to add some sql for changing role before the main query. Some of them doesn't return data, and causes exceptions here.

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

I use SQL_QUERY_MUTATOR to add some additional queries for changing role before the main query. Some of them doesn't return data, and causes exception here.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

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

REVIEWERS

I use SQL_QUERY_MUTATOR to add some sql for changing role before the main query. Some of them doesn't return data, and causes exceptions here.
try:
cursor.fetchall()
except BaseException:
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I might be missing something obvious here, but why are we calling fetchall() if we're not even storing the return value anywhere? Wouldn't it be enough to just call exexute() here and remove the fetch all together?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused about here too. We only want data from the last query.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah yes, it's explained here: #5517. I think this looks good, but it might be good to add a comment explaining that some engines require calling fetchall() to force the execute() calls to execute synchronously.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the raw connection exposes the underlying DB-API. Per PEP 249 the fetchall method raises an Error and thus sense we should use the SQLAlchemy equivalent exception here rather than BaseException.

Copy link
Member

@john-bodley john-bodley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Danielking could you provide more context (as well as a stack trace) as to when this fails. Note in general SQL exceptions should not be swallowed but captured and presented in the explorer as a message to inform the user of the problem.

@stale
Copy link

stale bot commented Jul 17, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

@stale stale bot added the inactive Inactive for >= 30 days label Jul 17, 2019
Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong and needs more context, we can't swallow all exceptions when fetching.

@stale stale bot removed the inactive Inactive for >= 30 days label Jul 18, 2019
@stale
Copy link

stale bot commented Sep 16, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

@stale stale bot added the inactive Inactive for >= 30 days label Sep 16, 2019
@stale stale bot closed this Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive Inactive for >= 30 days size/XS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants