Skip to content

[3.9] bpo-43434: Move sqlite3.connect audit event to sqlite3.Connection.__init__ (GH-25818) #25822

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
merged 3 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Creating a :class:`sqlite3.Connection` object now also produces
a ``sqlite3.connect`` :ref:`auditing event <auditing>`.
Previously this event was only produced by :func:`sqlite3.connect`
calls. Patch by Erlend E. Aasland.
4 changes: 4 additions & 0 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
return -1;
}

if (PySys_Audit("sqlite3.connect", "O", database_obj) < 0) {
return -1;
}

database = PyBytes_AsString(database_obj);

self->initialized = 1;
Expand Down
10 changes: 1 addition & 9 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
int uri = 0;
double timeout = 5.0;

PyObject* result;

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|diOiOip", kwlist,
&database, &timeout, &detect_types,
&isolation_level, &check_same_thread,
Expand All @@ -85,13 +83,7 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
factory = (PyObject*)&pysqlite_ConnectionType;
}

if (PySys_Audit("sqlite3.connect", "O", database) < 0) {
return NULL;
}

result = PyObject_Call(factory, args, kwargs);

return result;
return PyObject_Call(factory, args, kwargs);
}

PyDoc_STRVAR(module_connect_doc,
Expand Down