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
Conversation
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! |
Since this is just a tiny documentation fix, I think it warrants the "skip issue" and "skip news" labels. |
From the history of this file, I think @berkerpeksag may be a good person to review this. |
There was a problem hiding this 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:
cpython/Lib/sqlite3/test/hooks.py
Lines 175 to 189 in 4f469c0
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)") |
Doc/library/sqlite3.rst
Outdated
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:exc:`sqlite3.OperationalError`
Thanks @simonw for the PR, and @berkerpeksag for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6. |
Thanks! |
…onGH-4120) (cherry picked from commit ac03c03)
GH-4229 is a backport of this pull request to the 3.6 branch. |
…onGH-4120) (cherry picked from commit ac03c03)
) (cherry picked from commit ac03c03)
This behaviour is currently undocumented by Python, but is covered in the SQLite docs here: https://sqlite.org/c3ref/progress_handler.html