Skip to content

Commit f2c6a84

Browse files
Erlend Egeberg Aaslandadorilson
Erlend Egeberg Aasland
authored andcommitted
bpo-24464: Deprecate sqlite3.enable_shared_cache (pythonGH-24008)
1 parent 082a0a6 commit f2c6a84

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

Doc/whatsnew/3.10.rst

+8
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,14 @@ Deprecated
486486
scheduled for removal in Python 3.12.
487487
(Contributed by Erlend E. Aasland in :issue:`42264`.)
488488

489+
* The undocumented built-in function ``sqlite3.enable_shared_cache`` is now
490+
deprecated, scheduled for removal in Python 3.12. Its use is strongly
491+
discouraged by the SQLite3 documentation. See `the SQLite3 docs
492+
<https://sqlite.org/c3ref/enable_shared_cache.html/>`_ for more details.
493+
If shared cache must be used, open the database in URI mode using the
494+
``cache=shared`` query parameter.
495+
(Contributed by Erlend E. Aasland in :issue:`24464`.)
496+
489497

490498
Removed
491499
=======

Lib/sqlite3/dbapi2.py

+14
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+
def enable_shared_cache(enable):
90+
from _sqlite3 import enable_shared_cache as _old_enable_shared_cache
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

+7
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):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The undocumented built-in function ``sqlite3.enable_shared_cache`` is now
2+
deprecated, scheduled for removal in Python 3.12. Its use is strongly
3+
discouraged by the SQLite3 documentation. Patch by Erlend E. Aasland.

0 commit comments

Comments
 (0)