-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
bpo-42064: Pass module state to trace, progress, and authorizer callbacks #27940
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
Merged
encukou
merged 17 commits into
python:main
from
erlend-aasland:sqlite-callback-state/part2
Sep 7, 2021
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e4fe706
Adapt trace callback
8a9f9ab
Adapt progress handler
44c85b7
Adapt authoriser callback
7f3c64b
Add set context helper
4880b73
Free callback contexts after closing connection
3f5c0f4
Add print-or-clear-traceback helper
71f66ca
Ajdust comment
b8be981
Use SET_CALLBACK_CONTEXT in __init__
943ad79
Merge branch 'main' into sqlite-callback-state/part2
6f6bf1d
Include minor PEP 7 adjustment
3b97195
Address review: explicitly initialise authoriser callback return code
83ab097
Address review: implement CLEAR_CALLBACK_CONTEXT as a regular function
d0a422b
Merge branch 'main' into sqlite-callback-state/part2
32c2073
Fix merge
cb4063a
Make SET_CALLBACK_CONTEXT a regular function
e0df824
Let set_callback_context live with the other context functions
5ff1951
Remove spurious line break
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
These three statements are named
free_callback_contexts()below. But here they are problematic.PyType_GenericAllochas set all these to NULL and they don't need to be NULLed again.__init__for the second time, this might free the Python callable, but SQLite will still have the pointer. Also the olddbwill leak, and who knows what'll happen to old cursors… Whoa, I don't see how reinitialization could work; should it rather raise an 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.
I had reinitialisation in mind, but as you say, it's hard to imagine how to do that properly anyway. Maybe implicit connection close at the start of
__init__will do the trick. I'll have to think that through. Perhaps we should fix the reinit case before proceeding with this PR.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.
I would be surprised. Cursors seem to have hard (and reasonable!) assumptions about their connection's
db.I also don't see the use case – when would a new connection object not be enough?
Uh oh!
There was an error while loading. Please reload this page.
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.
Hm, true.
Let's raise an exception instead.I did some tests, and reinit actually seems to work pretty well using an implicit close in
__init__, even with dangling cursors that fetch and execute after reinit. There's no refleaks on our side, and SQLite seems to be able to clean up as well. The only improvement would be to clear the callbacks from SQLite before the implicit close.Me neither.
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.
I'm surprised. Wouldn't this result in a
sqlite3_open_v2without a corresponding close?Uh oh!
There was an error while loading. Please reload this page.
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.
Perhaps I was a little bit vague. I did the tests with an added implicit close in
__init__.Here's the diff I used:
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.
I see. Well, this is more complicated than I initially thought; I guess it should be a separate bpo issue.
I keep finding issues:
dbis not set to NULL if init fails.... and even if that's fixed, I'm concerned that there will be other edge cases we can't reasonably think about.
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.
Yes, there's some issues in connection init. I'd gladly clean it up and harden it before continuing with this PR.
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.
It's not a blocker for this PR; just please open a bpo so the issues won't be lost in a closed PR.
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.
I've opened issue 45126 for this.