Skip to content

Commit

Permalink
Fixed #6669 -- Ensured database connections are marked as dirty by Cu…
Browse files Browse the repository at this point in the history
…rsorDebugWrapper.execute/executemany. Refs #9964. Thanks james at 10gic net for the report and Claude Paroz for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17368 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
aaugustin committed Jan 12, 2012
1 parent e1ba911 commit 30c846b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django/db/backends/util.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ def __init__(self, cursor, db):
self.cursor = cursor self.cursor = cursor
self.db = db self.db = db


def __getattr__(self, attr): def set_dirty(self):
if self.db.is_managed(): if self.db.is_managed():
self.db.set_dirty() self.db.set_dirty()

def __getattr__(self, attr):
self.set_dirty()
if attr in self.__dict__: if attr in self.__dict__:
return self.__dict__[attr] return self.__dict__[attr]
else: else:
Expand All @@ -31,6 +34,7 @@ def __iter__(self):
class CursorDebugWrapper(CursorWrapper): class CursorDebugWrapper(CursorWrapper):


def execute(self, sql, params=()): def execute(self, sql, params=()):
self.set_dirty()
start = time() start = time()
try: try:
return self.cursor.execute(sql, params) return self.cursor.execute(sql, params)
Expand All @@ -47,6 +51,7 @@ def execute(self, sql, params=()):
) )


def executemany(self, sql, param_list): def executemany(self, sql, param_list):
self.set_dirty()
start = time() start = time()
try: try:
return self.cursor.executemany(sql, param_list) return self.cursor.executemany(sql, param_list)
Expand Down
8 changes: 8 additions & 0 deletions tests/regressiontests/transactions_regress/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db import connection, transaction from django.db import connection, transaction
from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError
from django.test import TransactionTestCase, skipUnlessDBFeature from django.test import TransactionTestCase, skipUnlessDBFeature
from django.test.utils import override_settings
from django.utils.unittest import skipIf from django.utils.unittest import skipIf


from .models import Mod, M2mA, M2mB from .models import Mod, M2mA, M2mB
Expand Down Expand Up @@ -166,6 +167,13 @@ def create_system_user():
except: except:
self.fail("A transaction consisting of a failed operation was not closed.") self.fail("A transaction consisting of a failed operation was not closed.")


@override_settings(DEBUG=True)
def test_failing_query_transaction_closed_debug(self):
"""
Regression for #6669. Same test as above, with DEBUG=True.
"""
self.test_failing_query_transaction_closed()



class TestManyToManyAddTransaction(TransactionTestCase): class TestManyToManyAddTransaction(TransactionTestCase):
def test_manyrelated_add_commit(self): def test_manyrelated_add_commit(self):
Expand Down

0 comments on commit 30c846b

Please sign in to comment.