Ticket #17760: 17760-5.diff

File 17760-5.diff, 8.9 KB (added by Claude Paroz, 13 years ago)

Updated to current trunk

  • django/contrib/gis/db/backends/spatialite/creation.py

    diff --git a/django/contrib/gis/db/backends/spatialite/creation.py b/django/contrib/gis/db/backends/spatialite/creation.py
    index 7efab3e..31f2fca 100644
    a b class SpatiaLiteCreation(DatabaseCreation):  
    3131        self.connection.close()
    3232        self.connection.settings_dict["NAME"] = test_database_name
    3333
    34         # Confirm the feature set of the test database
    35         self.connection.features.confirm()
    36 
    3734        # Need to load the SpatiaLite initialization SQL before running `syncdb`.
    3835        self.load_spatialite_sql()
    3936
  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    index f26653f..d70fe54 100644
    a b from django.conf import settings  
    1010from django.db import DEFAULT_DB_ALIAS
    1111from django.db.backends import util
    1212from django.db.transaction import TransactionManagementError
     13from django.utils.functional import cached_property
    1314from django.utils.importlib import import_module
    1415from django.utils.timezone import is_aware
    1516
    class BaseDatabaseFeatures(object):  
    402403    # Does the backend reset sequences between tests?
    403404    supports_sequence_reset = True
    404405
    405     # Features that need to be confirmed at runtime
    406     # Cache whether the confirmation has been performed.
    407     _confirmed = False
    408     supports_transactions = None
    409     supports_stddev = None
    410     can_introspect_foreign_keys = None
     406    # Confirm support for introspected foreign keys
     407    # Every database can do this reliably, except MySQL,
     408    # which can't do it for MyISAM tables
     409    can_introspect_foreign_keys = True
    411410
    412411    # Support for the DISTINCT ON clause
    413412    can_distinct_on_fields = False
    class BaseDatabaseFeatures(object):  
    415414    def __init__(self, connection):
    416415        self.connection = connection
    417416
    418     def confirm(self):
    419         "Perform manual checks of any database features that might vary between installs"
    420         if not self._confirmed:
    421             self._confirmed = True
    422             self.supports_transactions = self._supports_transactions()
    423             self.supports_stddev = self._supports_stddev()
    424             self.can_introspect_foreign_keys = self._can_introspect_foreign_keys()
    425 
    426     def _supports_transactions(self):
     417    @cached_property
     418    def supports_transactions(self):
    427419        "Confirm support for transactions"
    428420        cursor = self.connection.cursor()
    429421        cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
    class BaseDatabaseFeatures(object):  
    436428        self.connection._commit()
    437429        return count == 0
    438430
    439     def _supports_stddev(self):
     431    @cached_property
     432    def supports_stddev(self):
    440433        "Confirm support for STDDEV and related stats functions"
    441434        class StdDevPop(object):
    442435            sql_function = 'STDDEV_POP'
    class BaseDatabaseFeatures(object):  
    447440        except NotImplementedError:
    448441            return False
    449442
    450     def _can_introspect_foreign_keys(self):
    451         "Confirm support for introspected foreign keys"
    452         # Every database can do this reliably, except MySQL,
    453         # which can't do it for MyISAM tables
    454         return True
    455 
    456443
    457444class BaseDatabaseOperations(object):
    458445    """
  • django/db/backends/creation.py

    diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
    index ba90cb9..0f06131 100644
    a b class BaseDatabaseCreation(object):  
    264264        self.connection.close()
    265265        self.connection.settings_dict["NAME"] = test_database_name
    266266
    267         # Confirm the feature set of the test database
    268         self.connection.features.confirm()
    269 
    270267        # Report syncdb messages at one level lower than that requested.
    271268        # This ensures we don't get flooded with messages during testing
    272269        # (unless you really ask to be flooded)
  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    index 1df487b..1dbd91b 100644
    a b from django.db.backends.mysql.client import DatabaseClient  
    3636from django.db.backends.mysql.creation import DatabaseCreation
    3737from django.db.backends.mysql.introspection import DatabaseIntrospection
    3838from django.db.backends.mysql.validation import DatabaseValidation
     39from django.utils.functional import cached_property
    3940from django.utils.safestring import SafeString, SafeUnicode
    4041from django.utils import timezone
    4142
    class DatabaseFeatures(BaseDatabaseFeatures):  
    169170
    170171    def __init__(self, connection):
    171172        super(DatabaseFeatures, self).__init__(connection)
    172         self._storage_engine = None
    173173
     174    @cached_property
    174175    def _mysql_storage_engine(self):
    175176        "Internal method used in Django tests. Don't rely on this from your code"
    176         if self._storage_engine is None:
    177             cursor = self.connection.cursor()
    178             cursor.execute('CREATE TABLE INTROSPECT_TEST (X INT)')
    179             # This command is MySQL specific; the second column
    180             # will tell you the default table type of the created
    181             # table. Since all Django's test tables will have the same
    182             # table type, that's enough to evaluate the feature.
    183             cursor.execute("SHOW TABLE STATUS WHERE Name='INTROSPECT_TEST'")
    184             result = cursor.fetchone()
    185             cursor.execute('DROP TABLE INTROSPECT_TEST')
    186             self._storage_engine = result[1]
    187         return self._storage_engine
    188 
    189     def _can_introspect_foreign_keys(self):
     177        cursor = self.connection.cursor()
     178        cursor.execute('CREATE TABLE INTROSPECT_TEST (X INT)')
     179        # This command is MySQL specific; the second column
     180        # will tell you the default table type of the created
     181        # table. Since all Django's test tables will have the same
     182        # table type, that's enough to evaluate the feature.
     183        cursor.execute("SHOW TABLE STATUS WHERE Name='INTROSPECT_TEST'")
     184        result = cursor.fetchone()
     185        cursor.execute('DROP TABLE INTROSPECT_TEST')
     186        return result[1]
     187
     188    @cached_property
     189    def can_introspect_foreign_keys(self):
    190190        "Confirm support for introspected foreign keys"
    191         return self._mysql_storage_engine() != 'MyISAM'
     191        return self._mysql_storage_engine != 'MyISAM'
    192192
    193193class DatabaseOperations(BaseDatabaseOperations):
    194194    compiler_module = "django.db.backends.mysql.compiler"
  • django/db/backends/sqlite3/base.py

    diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
    index 4fba304..db6adde 100644
    a b from django.db.backends.sqlite3.client import DatabaseClient  
    1818from django.db.backends.sqlite3.creation import DatabaseCreation
    1919from django.db.backends.sqlite3.introspection import DatabaseIntrospection
    2020from django.utils.dateparse import parse_date, parse_datetime, parse_time
     21from django.utils.functional import cached_property
    2122from django.utils.safestring import SafeString
    2223from django.utils import timezone
    2324
    class DatabaseFeatures(BaseDatabaseFeatures):  
    8586    has_bulk_insert = True
    8687    can_combine_inserts_with_and_without_auto_increment_pk = True
    8788
    88     def _supports_stddev(self):
     89    @cached_property
     90    def supports_stddev(self):
    8991        """Confirm support for STDDEV and related stats functions
    9092
    9193        SQLite supports STDDEV as an extension package; so
  • tests/regressiontests/backends/tests.py

    diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
    index 109e1a5..9bee987 100644
    a b class BackendTestCase(TestCase):  
    403403        self.assertTrue(hasattr(connection.ops, 'connection'))
    404404        self.assertEqual(connection, connection.ops.connection)
    405405
    406     def test_supports_needed_confirm(self):
    407         connection.features.confirm()
     406    def test_cached_db_features(self):
    408407        self.assertIn(connection.features.supports_transactions, (True, False))
    409408        self.assertIn(connection.features.supports_stddev, (True, False))
    410409        self.assertIn(connection.features.can_introspect_foreign_keys, (True, False))
  • tests/regressiontests/transactions_regress/tests.py

    diff --git a/tests/regressiontests/transactions_regress/tests.py b/tests/regressiontests/transactions_regress/tests.py
    index 5972263..abd7a4c 100644
    a b class SavepointTest(TransactionTestCase):  
    208208        work()
    209209
    210210    @skipIf(connection.vendor == 'mysql' and \
    211             connection.features._mysql_storage_engine() == 'MyISAM',
     211            connection.features._mysql_storage_engine == 'MyISAM',
    212212            "MyISAM MySQL storage engine doesn't support savepoints")
    213213    @skipUnlessDBFeature('uses_savepoints')
    214214    def test_savepoint_rollback(self):
Back to Top