Fixed some locations to work with autocommit=True
- backends: supports_transactions() - select_for_update tests
This commit is contained in:
parent
bd283aa844
commit
da573fbb41
|
@ -417,6 +417,12 @@ class BaseDatabaseFeatures(object):
|
||||||
@cached_property
|
@cached_property
|
||||||
def supports_transactions(self):
|
def supports_transactions(self):
|
||||||
"Confirm support for transactions"
|
"Confirm support for transactions"
|
||||||
|
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 = self.connection.cursor()
|
||||||
cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
|
cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
|
||||||
self.connection._commit()
|
self.connection._commit()
|
||||||
|
@ -426,6 +432,9 @@ class BaseDatabaseFeatures(object):
|
||||||
count, = cursor.fetchone()
|
count, = cursor.fetchone()
|
||||||
cursor.execute('DROP TABLE ROLLBACK_TEST')
|
cursor.execute('DROP TABLE ROLLBACK_TEST')
|
||||||
self.connection._commit()
|
self.connection._commit()
|
||||||
|
self.connection._dirty = False
|
||||||
|
finally:
|
||||||
|
self.connection.leave_transaction_management()
|
||||||
return count == 0
|
return count == 0
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
|
|
@ -36,6 +36,8 @@ class SelectForUpdateTests(TransactionTestCase):
|
||||||
# issuing a SELECT ... FOR UPDATE will block.
|
# issuing a SELECT ... FOR UPDATE will block.
|
||||||
new_connections = ConnectionHandler(settings.DATABASES)
|
new_connections = ConnectionHandler(settings.DATABASES)
|
||||||
self.new_connection = new_connections[DEFAULT_DB_ALIAS]
|
self.new_connection = new_connections[DEFAULT_DB_ALIAS]
|
||||||
|
self.new_connection.enter_transaction_management()
|
||||||
|
self.new_connection.managed(True)
|
||||||
|
|
||||||
# We need to set settings.DEBUG to True so we can capture
|
# We need to set settings.DEBUG to True so we can capture
|
||||||
# the output SQL to examine.
|
# the output SQL to examine.
|
||||||
|
@ -48,6 +50,7 @@ class SelectForUpdateTests(TransactionTestCase):
|
||||||
# this in the course of their run.
|
# this in the course of their run.
|
||||||
transaction.managed(False)
|
transaction.managed(False)
|
||||||
transaction.leave_transaction_management()
|
transaction.leave_transaction_management()
|
||||||
|
self.new_connection.leave_transaction_management()
|
||||||
except transaction.TransactionManagementError:
|
except transaction.TransactionManagementError:
|
||||||
pass
|
pass
|
||||||
self.new_connection.close()
|
self.new_connection.close()
|
||||||
|
@ -66,7 +69,7 @@ class SelectForUpdateTests(TransactionTestCase):
|
||||||
'for_update': self.new_connection.ops.for_update_sql(),
|
'for_update': self.new_connection.ops.for_update_sql(),
|
||||||
}
|
}
|
||||||
self.cursor.execute(sql, ())
|
self.cursor.execute(sql, ())
|
||||||
result = self.cursor.fetchone()
|
self.cursor.fetchone()
|
||||||
|
|
||||||
def end_blocking_transaction(self):
|
def end_blocking_transaction(self):
|
||||||
# Roll back the blocking transaction.
|
# Roll back the blocking transaction.
|
||||||
|
|
Loading…
Reference in New Issue