Forbid queries in broken transactions #1659

Closed
wants to merge 5 commits into from

1 participant

@charettes charettes and 1 other commented on an outdated diff Sep 22, 2013
django/db/backends/__init__.py
@@ -638,6 +644,9 @@ class BaseDatabaseFeatures(object):
# when autocommit is disabled? http://bugs.python.org/issue8145#msg109965
autocommits_when_autocommit_is_off = False
+ # Does the backend prevent running SQL queries is broken transactions?
@charettes
Django member

... in broken transactions?

@aaugustin
Django member

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
aaugustin added some commits Sep 21, 2013
@aaugustin aaugustin Prevented running queries in transactions that will be rolled back.
This avoids a counter-intuitive behavior in an edge case on databases
with non-atomic transaction semantics.

It prevents using savepoint_rollback() inside an atomic block without
calling set_rollback(False) first, which is backwards-incompatible in
tests.

Refs #21134.
461ecec
@aaugustin aaugustin Replaced manual savepoints by atomic blocks.
This ensures the rollback flag is handled consistently in internal APIs.
f72fcd9
@aaugustin aaugustin Fixed TransactionManagementError in tests.
Previous commit introduced an additional check to prevent running
queries in transactions that will be rolled back, which triggered a few
failures in the tests. In practice using transaction.atomic instead of
the low-level savepoint APIs was enough to fix the problems.
08359d0
@aaugustin aaugustin Allowed nesting constraint_checks_disabled inside atomic.
Since MySQL handles transactions loosely, this isn't a problem.
13f9828
@aaugustin aaugustin Clarified interactions between atomic and exceptions. 40b69af
@aaugustin
Django member

Squashed and merged in 728548e.

@aaugustin aaugustin closed this Sep 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment