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

Returning 1 from the set_progress_handler handler cancels query #4120

Merged
merged 4 commits into from Nov 2, 2017

Conversation

simonw
Copy link
Contributor

@simonw simonw commented Oct 25, 2017

This behaviour is currently undocumented by Python, but is covered in the SQLite docs here: https://sqlite.org/c3ref/progress_handler.html

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@simonw
Copy link
Contributor Author

simonw commented Oct 26, 2017

Since this is just a tiny documentation fix, I think it warrants the "skip issue" and "skip news" labels.

@simonw
Copy link
Contributor Author

simonw commented Nov 1, 2017

From the history of this file, I think @berkerpeksag may be a good person to review this.

Copy link
Member

@berkerpeksag berkerpeksag left a comment

Choose a reason for hiding this comment

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

Good catch, thank you! This is indeed a tested but undocumented feature:

def CheckCancelOperation(self):
"""
Test that returning a non-zero value stops the operation in progress.
"""
con = sqlite.connect(":memory:")
progress_calls = []
def progress():
progress_calls.append(None)
return 1
con.set_progress_handler(progress, 1)
curs = con.cursor()
self.assertRaises(
sqlite.OperationalError,
curs.execute,
"create table bar (a, b)")

@@ -421,6 +421,10 @@ Connection Objects
If you want to clear any previously installed progress handler, call the
method with :const:`None` for *handler*.

Returning a non-zero value from the handler function will terminate the
currently executing query and cause it to raise a
``sqlite3.OperationalError`` exception.
Copy link
Member

Choose a reason for hiding this comment

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

:exc:`sqlite3.OperationalError`

@berkerpeksag berkerpeksag merged commit ac03c03 into python:master Nov 2, 2017
@miss-islington
Copy link
Contributor

Thanks @simonw for the PR, and @berkerpeksag for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@berkerpeksag
Copy link
Member

Thanks!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 2, 2017
@bedevere-bot
Copy link

GH-4229 is a backport of this pull request to the 3.6 branch.

berkerpeksag pushed a commit to berkerpeksag/cpython that referenced this pull request Nov 2, 2017
berkerpeksag added a commit that referenced this pull request Nov 2, 2017
embray pushed a commit to embray/cpython that referenced this pull request Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants