]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-93044: No longer convert the database argument of sqlite3.connect() to bytes ...
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 21 May 2022 11:35:46 +0000 (14:35 +0300)
committerGitHub <noreply@github.com>
Sat, 21 May 2022 11:35:46 +0000 (14:35 +0300)
Just pass it to the factory as is.

Lib/test/test_sqlite3/test_dbapi.py
Misc/NEWS.d/next/Library/2022-05-21-13-16-16.gh-issue-93044.eJ_XkZ.rst [new file with mode: 0644]
Modules/_sqlite/clinic/module.c.h
Modules/_sqlite/module.c

index 40f91a193b2cddcb0645022b6d2c43bd39cfc467..f0c009afe459b90e517b1d0b032ba1ebc7da667f 100644 (file)
@@ -676,6 +676,19 @@ class OpenTests(unittest.TestCase):
             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)
diff --git a/Misc/NEWS.d/next/Library/2022-05-21-13-16-16.gh-issue-93044.eJ_XkZ.rst b/Misc/NEWS.d/next/Library/2022-05-21-13-16-16.gh-issue-93044.eJ_XkZ.rst
new file mode 100644 (file)
index 0000000..c9df867
--- /dev/null
@@ -0,0 +1,2 @@
+No longer convert the database argument of :func:`sqlite3.connect` to bytes
+before passing it to the factory.
index 74a6a362c05abae454f4092f9bce52eb20005757..d3367cf62bf724a2ab7ff44d4c73966b49058742 100644 (file)
@@ -43,9 +43,7 @@ pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb
     if (!args) {
         goto exit;
     }
-    if (!PyUnicode_FSConverter(args[0], &database)) {
-        goto exit;
-    }
+    database = args[0];
     if (!noptargs) {
         goto skip_optional_pos;
     }
@@ -294,4 +292,4 @@ skip_optional:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=43aa4f4356f9269d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a7cfa6dc9d54273c input=a9049054013a1b77]*/
index 78591f85c1f7deb9c9eaaf146a6b0a159af56192..9b0e921511c56a688b30bd70f8f26c2a2ab84cb6 100644 (file)
@@ -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
@@ -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("");
@@ -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;
 }