Ticket #6669: 6669-2.diff

File 6669-2.diff, 2.4 KB (added by Claude Paroz, 12 years ago)

Set connection dirty even with CursorDebugWrapper

  • django/db/backends/util.py

    diff --git a/django/db/backends/util.py b/django/db/backends/util.py
    index b0463b7..56e350f 100644
    a b class CursorWrapper(object):  
    1616        self.cursor = cursor
    1717        self.db = db
    1818
    19     def __getattr__(self, attr):
     19    def _set_dirty(self):
    2020        if self.db.is_managed():
    2121            self.db.set_dirty()
     22
     23    def __getattr__(self, attr):
     24        self._set_dirty()
    2225        if attr in self.__dict__:
    2326            return self.__dict__[attr]
    2427        else:
    class CursorWrapper(object):  
    3134class CursorDebugWrapper(CursorWrapper):
    3235
    3336    def execute(self, sql, params=()):
     37        self._set_dirty()
    3438        start = time()
    3539        try:
    3640            return self.cursor.execute(sql, params)
    class CursorDebugWrapper(CursorWrapper):  
    4751            )
    4852
    4953    def executemany(self, sql, param_list):
     54        self._set_dirty()
    5055        start = time()
    5156        try:
    5257            return self.cursor.executemany(sql, param_list)
  • tests/regressiontests/transactions_regress/tests.py

    diff --git a/tests/regressiontests/transactions_regress/tests.py b/tests/regressiontests/transactions_regress/tests.py
    index 22f1b0f..5907c3a 100644
    a b  
    1 from __future__ import absolute_import
     1from __future__ import absolute_import, with_statement
    22
    33from django.core.exceptions import ImproperlyConfigured
    44from django.db import connection, transaction
    55from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError
     6from django.db.utils import DatabaseError
    67from django.test import TransactionTestCase, skipUnlessDBFeature
     8from django.test.utils import override_settings
    79from django.utils.unittest import skipIf
    810
    911from .models import Mod, M2mA, M2mB
    class TestTransactionClosing(TransactionTestCase):  
    166168        except:
    167169            self.fail("A transaction consisting of a failed operation was not closed.")
    168170
     171        # Same test with DebugCursor
     172        with override_settings(DEBUG=True):
     173            self.assertRaises(Exception, create_system_user)
     174            try:
     175                self.assertEqual(User.objects.count(), 1)
     176            except DatabaseError:
     177                self.fail("A transaction consisting of a failed operation was not closed.")
     178
    169179
    170180class TestManyToManyAddTransaction(TransactionTestCase):
    171181    def test_manyrelated_add_commit(self):
Back to Top