From 70f8bcaa53f730bb4abe0261908af47fee994518 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 8 Jan 2021 19:32:38 +0100 Subject: [PATCH 1/5] bpo-24464: Call sqlite3.enable_shared_cache() from deprecation wrapper --- Lib/sqlite3/dbapi2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/sqlite3/dbapi2.py b/Lib/sqlite3/dbapi2.py index 6475f98a646f9e..cfe6225f46efc0 100644 --- a/Lib/sqlite3/dbapi2.py +++ b/Lib/sqlite3/dbapi2.py @@ -96,7 +96,7 @@ def enable_shared_cache(enable): "the cache=shared query parameter." ) warnings.warn(msg, DeprecationWarning, stacklevel=2) - return _old_enable_shared_cache + return _old_enable_shared_cache(enable) # Clean up namespace From 260bbf3c7d6029b0448d948672f99350171a4d7a Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 8 Jan 2021 21:22:36 +0100 Subject: [PATCH 2/5] Fix test_shared_cache_deprecated on macOS --- Lib/sqlite3/test/dbapi.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py index 68a30622395325..b374ad7ee726ae 100644 --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/sqlite3/test/dbapi.py @@ -85,7 +85,12 @@ def test_not_supported_error(self): def test_shared_cache_deprecated(self): for enable in (True, False): with self.assertWarns(DeprecationWarning) as cm: - sqlite.enable_shared_cache(enable) + try: + sqlite.enable_shared_cache(enable) + except sqlite.OperationalError as err: + # See issue 24464 and https://sqlite.org/c3ref/enable_shared_cache.html + import sys + self.assertEqual(sys.platform, 'darwin') self.assertIn("dbapi.py", cm.filename) From 2eb92b6ccc18fe71bf38e1a45ed996ed537b245b Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 9 Jan 2021 10:03:10 +0100 Subject: [PATCH 3/5] Address review --- Lib/sqlite3/test/dbapi.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py index b374ad7ee726ae..00b0e4635f9db4 100644 --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/sqlite3/test/dbapi.py @@ -23,6 +23,7 @@ import threading import unittest import sqlite3 as sqlite +import sys # For test_shared_cache_deprecated from test.support.os_helper import TESTFN, unlink @@ -82,15 +83,11 @@ def test_not_supported_error(self): sqlite.DatabaseError), "NotSupportedError is not a subclass of DatabaseError") + @unittest.skipIf(sys.platform == 'darwin', 'shared cache is deprecated on macOS') def test_shared_cache_deprecated(self): + # See issue 24464: sqlite3_enable_shared_cache is deprecated on macOS for enable in (True, False): with self.assertWarns(DeprecationWarning) as cm: - try: - sqlite.enable_shared_cache(enable) - except sqlite.OperationalError as err: - # See issue 24464 and https://sqlite.org/c3ref/enable_shared_cache.html - import sys - self.assertEqual(sys.platform, 'darwin') self.assertIn("dbapi.py", cm.filename) From aecdd28b5937b188c4aa0df1d7e6e552ab626b7d Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 9 Jan 2021 10:20:12 +0100 Subject: [PATCH 4/5] Removed one line too many --- Lib/sqlite3/test/dbapi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py index 00b0e4635f9db4..5e482a1cccfcb5 100644 --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/sqlite3/test/dbapi.py @@ -88,6 +88,7 @@ def test_shared_cache_deprecated(self): # See issue 24464: sqlite3_enable_shared_cache is deprecated on macOS for enable in (True, False): with self.assertWarns(DeprecationWarning) as cm: + sqlite.enable_shared_cache(enable) self.assertIn("dbapi.py", cm.filename) From 83f1b74fc52da8b649db22ef8ec6031b5cdb21d7 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sat, 9 Jan 2021 13:00:59 +0200 Subject: [PATCH 5/5] Update dbapi.py --- Lib/sqlite3/test/dbapi.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py index 5e482a1cccfcb5..39c9bf5b61143d 100644 --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/sqlite3/test/dbapi.py @@ -23,7 +23,7 @@ import threading import unittest import sqlite3 as sqlite -import sys # For test_shared_cache_deprecated +import sys from test.support.os_helper import TESTFN, unlink @@ -83,9 +83,10 @@ def test_not_supported_error(self): sqlite.DatabaseError), "NotSupportedError is not a subclass of DatabaseError") - @unittest.skipIf(sys.platform == 'darwin', 'shared cache is deprecated on macOS') + # sqlite3_enable_shared_cache() is deprecated on macOS and calling it may raise + # OperationalError on some buildbots. + @unittest.skipIf(sys.platform == "darwin", "shared cache is deprecated on macOS") def test_shared_cache_deprecated(self): - # See issue 24464: sqlite3_enable_shared_cache is deprecated on macOS for enable in (True, False): with self.assertWarns(DeprecationWarning) as cm: sqlite.enable_shared_cache(enable)