Ticket #11665: 11665.1.diff

File 11665.1.diff, 2.4 KB (added by Ramiro Morales, 13 years ago)

Initial patch - It causes six ERRORs in the multiple_database regression tests

  • django/db/backends/__init__.py

    diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
    a b  
    255255    def make_debug_cursor(self, cursor):
    256256        return util.CursorDebugWrapper(cursor, self)
    257257
     258    def check_constraints(self):
     259        sql = self.ops.check_constraints_sql()
     260        for s in sql:
     261            self.cursor().execute(s)
     262
    258263class BaseDatabaseFeatures(object):
    259264    allows_group_by_pk = False
    260265    # True if django.db.backend.utils.typecast_timestamp is used on values
     
    440445        """
    441446        return ''
    442447
     448    def check_constraints_sql(self):
     449        """
     450        Returns the SQL necessary to force deferred constraints to be checked.
     451        """
     452        return []
     453
    443454    def drop_foreignkey_sql(self):
    444455        """
    445456        Returns the SQL command that drops a foreign key.
  • django/db/backends/postgresql_psycopg2/operations.py

    diff --git a/django/db/backends/postgresql_psycopg2/operations.py b/django/db/backends/postgresql_psycopg2/operations.py
    a b  
    4848    def deferrable_sql(self):
    4949        return " DEFERRABLE INITIALLY DEFERRED"
    5050
     51    def check_constraints_sql(self):
     52        return ["SET CONSTRAINTS ALL IMMEDIATE"]
     53
    5154    def lookup_cast(self, lookup_type):
    5255        lookup = '%s'
    5356
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    a b  
    304304    def _post_teardown(self):
    305305        """ Performs any post-test things. This includes:
    306306
     307            * Tearing down database fixtures, if any.
    307308            * Putting back the original ROOT_URLCONF if it was changed.
    308309            * Force closing the connection, so that the next test gets
    309310              a clean cursor.
     
    597598
    598599        restore_transaction_methods()
    599600        for db in databases:
    600             transaction.rollback(using=db)
    601             transaction.leave_transaction_management(using=db)
     601            # Force constraints check execution (on backends that support
     602            # deferring them) before rolling back the transaction.
     603            try:
     604                connections[db].check_constraints()
     605            finally:
     606                transaction.rollback(using=db)
     607                transaction.leave_transaction_management(using=db)
    602608
    603609def _deferredSkip(condition, reason):
    604610    def decorator(test_func):
Back to Top