Code

Ticket #18334: 18334-2.diff

File 18334-2.diff, 2.2 KB (added by claudep, 2 years ago)

Test included

Line 
1diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
2index 2762350..bf622b9 100644
3--- a/django/db/backends/__init__.py
4+++ b/django/db/backends/__init__.py
5@@ -414,10 +414,11 @@ class BaseDatabaseFeatures(object):
6 
7     def confirm(self):
8         "Perform manual checks of any database features that might vary between installs"
9-        self._confirmed = True
10-        self.supports_transactions = self._supports_transactions()
11-        self.supports_stddev = self._supports_stddev()
12-        self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
13+        if not self._confirmed:
14+            self._confirmed = True
15+            self.supports_transactions = self._supports_transactions()
16+            self.supports_stddev = self._supports_stddev()
17+            self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
18 
19     def _supports_transactions(self):
20         "Confirm support for transactions"
21@@ -439,8 +440,9 @@ class BaseDatabaseFeatures(object):
22 
23         try:
24             self.connection.ops.check_aggregate_support(StdDevPop())
25+            return True
26         except NotImplementedError:
27-            self.supports_stddev = False
28+            return False
29 
30     def _can_introspect_foreign_keys(self):
31         "Confirm support for introspected foreign keys"
32diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
33index eec817c..10e69b6 100644
34--- a/tests/regressiontests/backends/tests.py
35+++ b/tests/regressiontests/backends/tests.py
36@@ -397,6 +397,12 @@ class BackendTestCase(TestCase):
37         self.assertTrue(hasattr(connection.ops, 'connection'))
38         self.assertEqual(connection, connection.ops.connection)
39 
40+    def test_supports_needed_confirm(self):
41+        connection.features.confirm()
42+        self.assertIn(connection.features.supports_transactions, (True, False))
43+        self.assertIn(connection.features.supports_stddev, (True, False))
44+        self.assertIn(connection.features.can_introspect_foreign_keys, (True, False))
45+
46     def test_duplicate_table_error(self):
47         """ Test that creating an existing table returns a DatabaseError """
48         cursor = connection.cursor()