Fixed #27504 -- Allowed using the ORM after an error and rollback when autocommit is off.
This commit is contained in:
parent
b5ef90192f
commit
2742901ac2
|
@ -267,7 +267,7 @@ class BaseDatabaseWrapper(object):
|
|||
self._rollback()
|
||||
# A successful rollback means that the database connection works.
|
||||
self.errors_occurred = False
|
||||
|
||||
self.needs_rollback = False
|
||||
self.run_on_commit = []
|
||||
|
||||
def close(self):
|
||||
|
|
|
@ -443,8 +443,28 @@ class AtomicMiscTests(TransactionTestCase):
|
|||
# This is expected to fail because the savepoint no longer exists.
|
||||
connection.savepoint_rollback(sid)
|
||||
|
||||
@skipIf(connection.features.autocommits_when_autocommit_is_off,
|
||||
"This test requires a non-autocommit mode that doesn't autocommit.")
|
||||
|
||||
@skipIf(
|
||||
connection.features.autocommits_when_autocommit_is_off,
|
||||
"This test requires a non-autocommit mode that doesn't autocommit."
|
||||
)
|
||||
class NonAutocommitTests(TransactionTestCase):
|
||||
|
||||
available_apps = []
|
||||
|
||||
def test_orm_query_after_error_and_rollback(self):
|
||||
"""
|
||||
ORM queries are allowed after an error and a rollback in non-autocommit
|
||||
mode (#27504).
|
||||
"""
|
||||
transaction.set_autocommit(False)
|
||||
r1 = Reporter.objects.create(first_name='Archibald', last_name='Haddock')
|
||||
r2 = Reporter(first_name='Cuthbert', last_name='Calculus', id=r1.id)
|
||||
with self.assertRaises(IntegrityError):
|
||||
r2.save(force_insert=True)
|
||||
transaction.rollback()
|
||||
Reporter.objects.last()
|
||||
|
||||
def test_orm_query_without_autocommit(self):
|
||||
"""#24921 -- ORM queries must be possible after set_autocommit(False)."""
|
||||
transaction.set_autocommit(False)
|
||||
|
|
Loading…
Reference in New Issue