Ticket #18334: 18334-2.diff

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

Test included

  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index 2762350..bf622b9 100644
    a b class BaseDatabaseFeatures(object): 
    414414
    415415    def confirm(self):
    416416        "Perform manual checks of any database features that might vary between installs"
    417         self._confirmed = True
    418         self.supports_transactions = self._supports_transactions()
    419         self.supports_stddev = self._supports_stddev()
    420         self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
     417        if not self._confirmed:
     418            self._confirmed = True
     419            self.supports_transactions = self._supports_transactions()
     420            self.supports_stddev = self._supports_stddev()
     421            self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
    421422
    422423    def _supports_transactions(self):
    423424        "Confirm support for transactions"
    class BaseDatabaseFeatures(object): 
    439440
    440441        try:
    441442            self.connection.ops.check_aggregate_support(StdDevPop())
     443            return True
    442444        except NotImplementedError:
    443             self.supports_stddev = False
     445            return False
    444446
    445447    def _can_introspect_foreign_keys(self):
    446448        "Confirm support for introspected foreign keys"
  • tests/regressiontests/backends/tests.py

    diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
    index eec817c..10e69b6 100644
    a b class BackendTestCase(TestCase): 
    397397        self.assertTrue(hasattr(connection.ops, 'connection'))
    398398        self.assertEqual(connection, connection.ops.connection)
    399399
     400    def test_supports_needed_confirm(self):
     401        connection.features.confirm()
     402        self.assertIn(connection.features.supports_transactions, (True, False))
     403        self.assertIn(connection.features.supports_stddev, (True, False))
     404        self.assertIn(connection.features.can_introspect_foreign_keys, (True, False))
     405
    400406    def test_duplicate_table_error(self):
    401407        """ Test that creating an existing table returns a DatabaseError """
    402408        cursor = connection.cursor()
Back to Top