From da573fbb4172fb962c9f021fc0c03cf91b13e746 Mon Sep 17 00:00:00 2001 From: Anssi Kääriäinen Date: Sun, 27 May 2012 02:24:57 +0300 Subject: Fixed some locations to work with autocommit=True - backends: supports_transactions() - select_for_update tests --- django/db/backends/__init__.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'django') diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index d70fe54bdb..dab9b7e213 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -417,15 +417,24 @@ class BaseDatabaseFeatures(object): @cached_property def supports_transactions(self): "Confirm support for transactions" - cursor = self.connection.cursor() - cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)') - self.connection._commit() - cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)') - self.connection._rollback() - cursor.execute('SELECT COUNT(X) FROM ROLLBACK_TEST') - count, = cursor.fetchone() - cursor.execute('DROP TABLE ROLLBACK_TEST') - self.connection._commit() + try: + # Make sure to run inside a managed transaction block, + # otherwise autocommit will cause the confimation to + # fail. + self.connection.enter_transaction_management() + self.connection.managed(True) + cursor = self.connection.cursor() + cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)') + self.connection._commit() + cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)') + self.connection._rollback() + cursor.execute('SELECT COUNT(X) FROM ROLLBACK_TEST') + count, = cursor.fetchone() + cursor.execute('DROP TABLE ROLLBACK_TEST') + self.connection._commit() + self.connection._dirty = False + finally: + self.connection.leave_transaction_management() return count == 0 @cached_property -- cgit v1.3