Skip to content

Commit

Permalink
bpo-43434: Move sqlite3.connect audit events to sqlite3.Connection.__…
Browse files Browse the repository at this point in the history
…init__ (GH-25818)

(cherry picked from commit c96cc08)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
  • Loading branch information
Erlend Egeberg Aasland committed May 2, 2021
1 parent db3ce79 commit 10665ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
@@ -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
Expand Up @@ -98,6 +98,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
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

0 comments on commit 10665ac

Please sign in to comment.