Skip to content

Commit 4969fef

Browse files
author
Erlend E. Aasland
committed
bpo-24464: Deprecate sqlite3.enable_shared_cache
1 parent 2edfc86 commit 4969fef

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,14 @@ Deprecated
462462
scheduled for removal in Python 3.12.
463463
(Contributed by Erlend E. Aasland in :issue:`42264`.)
464464

465+
* ``sqlite3.enable_shared_cache`` is now deprecated, scheduled for removal in
466+
Python 3.12. The method is undocumented, and it's use is strongly
467+
discouraged by the SQLite3 documentation. See `the SQLite3 docs
468+
<https://sqlite.org/c3ref/enable_shared_cache.html/>` for more details. If
469+
shared cache must be used, open the database in URI mode using the
470+
``cache=shared`` query parameter.
471+
(Contributed by Erlend E. Aasland in :issue:`24464`.)
472+
465473

466474
Removed
467475
=======

Lib/sqlite3/dbapi2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ def convert_timestamp(val):
8484

8585
register_adapters_and_converters()
8686

87+
# bpo-24464: enable_shared_cache was deprecated in Python 3.10. It's
88+
# scheduled for removal in Python 3.12.
89+
_old_enable_shared_cache = enable_shared_cache
90+
def enable_shared_cache(enable):
91+
import warnings
92+
msg = ("""
93+
enable_shared_cache is deprecated and will be removed in Python 3.12.
94+
Shared cache is strongly discouraged by the SQLite 3 documentation.
95+
If shared cache must be used, open the database in URI mode using
96+
the cache=shared query parameter.
97+
""")
98+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
99+
return _old_enable_shared_cache
100+
87101
# Clean up namespace
88102

89103
del(register_adapters_and_converters)

Lib/sqlite3/test/dbapi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ def CheckNotSupportedError(self):
8383
sqlite.DatabaseError),
8484
"NotSupportedError is not a subclass of DatabaseError")
8585

86+
def CheckSharedCacheDeprecated(self):
87+
for enable in (True, False):
88+
with self.assertWarns(DeprecationWarning) as cm:
89+
sqlite.enable_shared_cache(enable)
90+
self.assertIn("dbapi.py", cm.filename)
91+
92+
8693
class ConnectionTests(unittest.TestCase):
8794

8895
def setUp(self):

0 commit comments

Comments
 (0)