| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
On hold until #27934 is merged. There should be no conflicts with #27931. This PR will need a rebase after #27934 is merged. |
Sorry, something went wrong.
There was a problem hiding this comment.
Nitpick:
SET_CALLBACK_CONTEXT and CLEAR_CALLBACK_CONTEXT can both be regular functions rather than macros, making them shorter and more readable.
That leaves VISIT_CALLBACK_CONTEXT, which I think is too robust for the 3 uses. But that's very much a personal opinion.
Sorry, something went wrong.
| SET_CALLBACK_CONTEXT(self->trace_ctx, NULL); | ||
| SET_CALLBACK_CONTEXT(self->progress_ctx, NULL); | ||
| SET_CALLBACK_CONTEXT(self->authorizer_ctx, NULL); |
There was a problem hiding this comment.
These three statements are named free_callback_contexts() below. But here they are problematic.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
Maybe implicit connection close at the start of __init__ will do the trick.
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?
Sorry, something went wrong.
There was a problem hiding this comment.
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.
I also don't see the use case
Me neither.
Sorry, something went wrong.
There was a problem hiding this comment.
There's no refleaks on our side, and SQLite seems to be able to clean up as well.
I'm surprised. Wouldn't this result in a sqlite3_open_v2 without a corresponding close?
Sorry, something went wrong.
There was a problem hiding this comment.
Perhaps I was a little bit vague. I did the tests with an added implicit close in __init__.
Here's the diff I used:
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 63fd916662..961afe8de0 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -56,6 +56,7 @@ static const char * const begin_statements[] = {
static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored));
static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
static void free_callback_context(callback_context *ctx);
+static void connection_close(pysqlite_Connection *self);
static PyObject *
new_statement_cache(pysqlite_Connection *self, int maxsize)
@@ -114,6 +115,18 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
return -1;
}
+ // Gracefully handle reinitialization
+ if (self->initialized) {
+ (void)sqlite3_set_authorizer(self->db, NULL, NULL);
+ sqlite3_progress_handler(self->db, 0, NULL, NULL);
+#ifdef HAVE_TRACE_V2
+ sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, NULL, NULL);
+#else
+ sqlite3_trace(self->db, NULL, NULL);
+#endif
+ connection_close(self);
+ }
+
pysqlite_state *state = pysqlite_get_state_by_type(Py_TYPE(self));
self->state = state;
Sorry, something went wrong.
There was a problem hiding this comment.
I see. Well, this is more complicated than I initially thought; I guess it should be a separate bpo issue.
I keep finding issues:
import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute('CREATE TABLE foo (bar)')
try:
conn.__init__('/bad-file/')
except sqlite3.OperationalError:
pass
conn.execute('INSERT INTO foo (bar) VALUES (1), (2), (3), (4)')... and even if that's fixed, I'm concerned that there will be other edge cases we can't reasonably think about.
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, there's some issues in connection init. I'd gladly clean it up and harden it before continuing with this PR.
Sorry, something went wrong.
There was a problem hiding this comment.
It's not a blocker for this PR; just please open a bpo so the issues won't be lost in a closed PR.
Sorry, something went wrong.
There was a problem hiding this comment.
I've opened issue 45126 for this.
Sorry, something went wrong.
|
Sorry, something went wrong.
|
NB, this needs to be rebased onto main after #28088 is merged, assuming of course that it'll be easier to land that PR. |
Sorry, something went wrong.
Personally I'd prefer a type-safe function with a more complex argument, but as I said, this is nitpicking. Feel free to make them all macros for consistency, if you find it easier to read :) I plan to review #28088 first. |
Sorry, something went wrong.
I'll keep VISIT_CALLBACK_CONTEXT function a macro in any case, but I'll think thrice about SET_CALLBACK_CONTEXT before deciding :)
Great, thanks! BTW, I'm creating a bpo for cleaning up connection __init__; I've got a WIP branch lying around already, so you can expect a PR anytime soon :) |
Sorry, something went wrong.
|
All right, no more changes comin' up, unless you've got further remarks :) |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks good, thanks!
Sorry, something went wrong.
Likewise! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
https://bugs.python.org/issue42064