Skip to content

Commit 14c0d33

Browse files
gh-93044: No longer convert the database argument of sqlite3.connect() to bytes (GH-93046)
Just pass it to the factory as is.
1 parent b96e20c commit 14c0d33

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

Lib/test/test_sqlite3/test_dbapi.py

+13
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,19 @@ def test_open_uri(self):
676676
with managed_connect(f"file:{TESTFN}?mode=ro", uri=True) as cx:
677677
cx.execute(self._sql)
678678

679+
def test_factory_database_arg(self):
680+
def factory(database, *args, **kwargs):
681+
nonlocal database_arg
682+
database_arg = database
683+
return sqlite.Connection(":memory:", *args, **kwargs)
684+
685+
for database in (TESTFN, os.fsencode(TESTFN),
686+
FakePath(TESTFN), FakePath(os.fsencode(TESTFN))):
687+
database_arg = None
688+
with sqlite.connect(database, factory=factory):
689+
pass
690+
self.assertEqual(database_arg, database)
691+
679692
def test_database_keyword(self):
680693
with sqlite.connect(database=":memory:") as cx:
681694
self.assertEqual(type(cx), sqlite.Connection)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
No longer convert the database argument of :func:`sqlite3.connect` to bytes
2+
before passing it to the factory.

Modules/_sqlite/clinic/module.c.h

+2-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/module.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module _sqlite3
4646
/*[clinic input]
4747
_sqlite3.connect as pysqlite_connect
4848
49-
database: object(converter='PyUnicode_FSConverter')
49+
database: object
5050
timeout: double = 5.0
5151
detect_types: int = 0
5252
isolation_level: object = NULL
@@ -66,7 +66,7 @@ pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout,
6666
int detect_types, PyObject *isolation_level,
6767
int check_same_thread, PyObject *factory,
6868
int cached_statements, int uri)
69-
/*[clinic end generated code: output=450ac9078b4868bb input=ea6355ba55a78e12]*/
69+
/*[clinic end generated code: output=450ac9078b4868bb input=e16914663ddf93ce]*/
7070
{
7171
if (isolation_level == NULL) {
7272
isolation_level = PyUnicode_FromString("");
@@ -81,7 +81,6 @@ pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout,
8181
timeout, detect_types,
8282
isolation_level, check_same_thread,
8383
factory, cached_statements, uri);
84-
Py_DECREF(database); // needed bco. the AC FSConverter
8584
Py_DECREF(isolation_level);
8685
return res;
8786
}

0 commit comments

Comments
 (0)