Skip to content

Commit ad73d16

Browse files
author
Erlend Egeberg Aasland
authored
bpo-43434: Move sqlite3.connect audit event to sqlite3.Connection.__init__ (GH-25818)
1 parent e60b1e1 commit ad73d16

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Creating a :class:`sqlite3.Connection` object now also produces
2+
a ``sqlite3.connect`` :ref:`auditing event <auditing>`.
3+
Previously this event was only produced by :func:`sqlite3.connect`
4+
calls. Patch by Erlend E. Aasland.

Modules/_sqlite/connection.c

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
9696
return -1;
9797
}
9898

99+
if (PySys_Audit("sqlite3.connect", "O", database_obj) < 0) {
100+
return -1;
101+
}
102+
99103
database = PyBytes_AsString(database_obj);
100104

101105
self->initialized = 1;

Modules/_sqlite/module.c

+1-9
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
7171
int uri = 0;
7272
double timeout = 5.0;
7373

74-
PyObject* result;
75-
7674
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|diOiOip", kwlist,
7775
&database, &timeout, &detect_types,
7876
&isolation_level, &check_same_thread,
@@ -85,13 +83,7 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
8583
factory = (PyObject*)&pysqlite_ConnectionType;
8684
}
8785

88-
if (PySys_Audit("sqlite3.connect", "O", database) < 0) {
89-
return NULL;
90-
}
91-
92-
result = PyObject_Call(factory, args, kwargs);
93-
94-
return result;
86+
return PyObject_Call(factory, args, kwargs);
9587
}
9688

9789
PyDoc_STRVAR(module_connect_doc,

0 commit comments

Comments
 (0)