Skip to content

Commit

Permalink
gh-93044: No longer convert the database argument of sqlite3.connect(…
Browse files Browse the repository at this point in the history
…) to bytes (GH-93046)

Just pass it to the factory as is.
  • Loading branch information
serhiy-storchaka committed May 21, 2022
1 parent b96e20c commit 14c0d33
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
13 changes: 13 additions & 0 deletions Lib/test/test_sqlite3/test_dbapi.py
Expand Up @@ -676,6 +676,19 @@ def test_open_uri(self):
with managed_connect(f"file:{TESTFN}?mode=ro", uri=True) as cx:
cx.execute(self._sql)

def test_factory_database_arg(self):
def factory(database, *args, **kwargs):
nonlocal database_arg
database_arg = database
return sqlite.Connection(":memory:", *args, **kwargs)

for database in (TESTFN, os.fsencode(TESTFN),
FakePath(TESTFN), FakePath(os.fsencode(TESTFN))):
database_arg = None
with sqlite.connect(database, factory=factory):
pass
self.assertEqual(database_arg, database)

def test_database_keyword(self):
with sqlite.connect(database=":memory:") as cx:
self.assertEqual(type(cx), sqlite.Connection)
Expand Down
@@ -0,0 +1,2 @@
No longer convert the database argument of :func:`sqlite3.connect` to bytes
before passing it to the factory.
6 changes: 2 additions & 4 deletions Modules/_sqlite/clinic/module.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Modules/_sqlite/module.c
Expand Up @@ -46,7 +46,7 @@ module _sqlite3
/*[clinic input]
_sqlite3.connect as pysqlite_connect
database: object(converter='PyUnicode_FSConverter')
database: object
timeout: double = 5.0
detect_types: int = 0
isolation_level: object = NULL
Expand All @@ -66,7 +66,7 @@ pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout,
int detect_types, PyObject *isolation_level,
int check_same_thread, PyObject *factory,
int cached_statements, int uri)
/*[clinic end generated code: output=450ac9078b4868bb input=ea6355ba55a78e12]*/
/*[clinic end generated code: output=450ac9078b4868bb input=e16914663ddf93ce]*/
{
if (isolation_level == NULL) {
isolation_level = PyUnicode_FromString("");
Expand All @@ -81,7 +81,6 @@ pysqlite_connect_impl(PyObject *module, PyObject *database, double timeout,
timeout, detect_types,
isolation_level, check_same_thread,
factory, cached_statements, uri);
Py_DECREF(database); // needed bco. the AC FSConverter
Py_DECREF(isolation_level);
return res;
}
Expand Down

0 comments on commit 14c0d33

Please sign in to comment.