Skip to content

Commit

Permalink
bpo-24464: Deprecate sqlite3.enable_shared_cache (GH-24008)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erlend Egeberg Aasland committed Jan 6, 2021
1 parent f9949f8 commit ddb5e11
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======
Expand Down
14 changes: 14 additions & 0 deletions Lib/sqlite3/dbapi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ def convert_timestamp(val):

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

This comment has been minimized.

Copy link
@mrluanma

mrluanma Jan 8, 2021

@erlend-aasland Shoud this be _old_enable_shared_cache(enable) ?

This comment has been minimized.

Copy link
@erlend-aasland

erlend-aasland Jan 8, 2021

Contributor

Yes, thanks for spotting this. I'll fix it.


# Clean up namespace

del(register_adapters_and_converters)
7 changes: 7 additions & 0 deletions Lib/sqlite3/test/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def CheckNotSupportedError(self):
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit ddb5e11

Please sign in to comment.