]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-24464: Deprecate sqlite3.enable_shared_cache (GH-24008)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Wed, 6 Jan 2021 00:36:04 +0000 (01:36 +0100)
committerGitHub <noreply@github.com>
Wed, 6 Jan 2021 00:36:04 +0000 (02:36 +0200)
Doc/whatsnew/3.10.rst
Lib/sqlite3/dbapi2.py
Lib/sqlite3/test/dbapi.py
Misc/NEWS.d/next/Library/2020-12-30-14-56-25.bpo-24464.vbNVHe.rst [new file with mode: 0644]

index 444f1326e5bd2e696f9d6cfeefd5867f39cd7c44..e615574fb2fab5231ac9f3d059b325945083ae6b 100644 (file)
@@ -486,6 +486,14 @@ Deprecated
   scheduled for removal in Python 3.12.
   (Contributed by Erlend E. Aasland in :issue:`42264`.)
 
+* The undocumented built-in function ``sqlite3.enable_shared_cache`` is now
+  deprecated, scheduled for removal in Python 3.12.  Its use is strongly
+  discouraged by the SQLite3 documentation.  See `the SQLite3 docs
+  <https://sqlite.org/c3ref/enable_shared_cache.html/>`_ for more details.
+  If shared cache must be used, open the database in URI mode using the
+  ``cache=shared`` query parameter.
+  (Contributed by Erlend E. Aasland in :issue:`24464`.)
+
 
 Removed
 =======
index 991682ce9ef3b732d471219c82c47399f95c9cef..6475f98a646f9e62085066edae0750f51457062b 100644 (file)
@@ -84,6 +84,20 @@ def register_adapters_and_converters():
 
 register_adapters_and_converters()
 
+# bpo-24464: enable_shared_cache was deprecated in Python 3.10.  It's
+# scheduled for removal in Python 3.12.
+def enable_shared_cache(enable):
+    from _sqlite3 import enable_shared_cache as _old_enable_shared_cache
+    import warnings
+    msg = (
+        "enable_shared_cache is deprecated and will be removed in Python 3.12. "
+        "Shared cache is strongly discouraged by the SQLite 3 documentation. "
+        "If shared cache must be used, open the database in URI mode using"
+        "the cache=shared query parameter."
+    )
+    warnings.warn(msg, DeprecationWarning, stacklevel=2)
+    return _old_enable_shared_cache
+
 # Clean up namespace
 
 del(register_adapters_and_converters)
index 2b85ef99f0233df8245d3df0c42c4b02bc374155..3131c1ec2ab14b9314bbc4f9c27753e2b29f6e32 100644 (file)
@@ -83,6 +83,13 @@ class ModuleTests(unittest.TestCase):
                                    sqlite.DatabaseError),
                         "NotSupportedError is not a subclass of DatabaseError")
 
+    def CheckSharedCacheDeprecated(self):
+        for enable in (True, False):
+            with self.assertWarns(DeprecationWarning) as cm:
+                sqlite.enable_shared_cache(enable)
+            self.assertIn("dbapi.py", cm.filename)
+
+
 class ConnectionTests(unittest.TestCase):
 
     def setUp(self):
diff --git a/Misc/NEWS.d/next/Library/2020-12-30-14-56-25.bpo-24464.vbNVHe.rst b/Misc/NEWS.d/next/Library/2020-12-30-14-56-25.bpo-24464.vbNVHe.rst
new file mode 100644 (file)
index 0000000..2039c1c
--- /dev/null
@@ -0,0 +1,3 @@
+The undocumented built-in function ``sqlite3.enable_shared_cache`` is now
+deprecated, scheduled for removal in Python 3.12.  Its use is strongly
+discouraged by the SQLite3 documentation.  Patch by Erlend E. Aasland.