Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed some locations to work with autocommit=True

 - backends: supports_transactions()
 - select_for_update tests
  • Loading branch information...
commit da573fbb4172fb962c9f021fc0c03cf91b13e746 1 parent bd283aa
Anssi Kääriäinen authored May 27, 2012
27  django/db/backends/__init__.py
@@ -417,15 +417,24 @@ def __init__(self, connection):
417 417
     @cached_property
418 418
     def supports_transactions(self):
419 419
         "Confirm support for transactions"
420  
-        cursor = self.connection.cursor()
421  
-        cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
422  
-        self.connection._commit()
423  
-        cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)')
424  
-        self.connection._rollback()
425  
-        cursor.execute('SELECT COUNT(X) FROM ROLLBACK_TEST')
426  
-        count, = cursor.fetchone()
427  
-        cursor.execute('DROP TABLE ROLLBACK_TEST')
428  
-        self.connection._commit()
  420
+        try:
  421
+            # Make sure to run inside a managed transaction block,
  422
+            # otherwise autocommit will cause the confimation to
  423
+            # fail.
  424
+            self.connection.enter_transaction_management()
  425
+            self.connection.managed(True)
  426
+            cursor = self.connection.cursor()
  427
+            cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
  428
+            self.connection._commit()
  429
+            cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)')
  430
+            self.connection._rollback()
  431
+            cursor.execute('SELECT COUNT(X) FROM ROLLBACK_TEST')
  432
+            count, = cursor.fetchone()
  433
+            cursor.execute('DROP TABLE ROLLBACK_TEST')
  434
+            self.connection._commit()
  435
+            self.connection._dirty = False
  436
+        finally:
  437
+            self.connection.leave_transaction_management()
429 438
         return count == 0
430 439
 
431 440
     @cached_property
5  tests/modeltests/select_for_update/tests.py
@@ -36,6 +36,8 @@ def setUp(self):
36 36
         # issuing a SELECT ... FOR UPDATE will block.
37 37
         new_connections = ConnectionHandler(settings.DATABASES)
38 38
         self.new_connection = new_connections[DEFAULT_DB_ALIAS]
  39
+        self.new_connection.enter_transaction_management()
  40
+        self.new_connection.managed(True)
39 41
 
40 42
         # We need to set settings.DEBUG to True so we can capture
41 43
         # the output SQL to examine.
@@ -48,6 +50,7 @@ def tearDown(self):
48 50
             # this in the course of their run.
49 51
             transaction.managed(False)
50 52
             transaction.leave_transaction_management()
  53
+            self.new_connection.leave_transaction_management()
51 54
         except transaction.TransactionManagementError:
52 55
             pass
53 56
         self.new_connection.close()
@@ -66,7 +69,7 @@ def start_blocking_transaction(self):
66 69
             'for_update': self.new_connection.ops.for_update_sql(),
67 70
             }
68 71
         self.cursor.execute(sql, ())
69  
-        result = self.cursor.fetchone()
  72
+        self.cursor.fetchone()
70 73
 
71 74
     def end_blocking_transaction(self):
72 75
         # Roll back the blocking transaction.

0 notes on commit da573fb

Please sign in to comment.
Something went wrong with that request. Please try again.