mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #24921 -- set_autocommit(False) + ORM queries.
This commits lifts the restriction that the outermost atomic block must be declared with savepoint=False. This restriction was overly cautious. The logic that makes it safe not to create savepoints for inner blocks also applies to the outermost block when autocommit is disabled and a transaction is already active. This makes it possible to use the ORM after set_autocommit(False). Previously it didn't work because ORM write operations are protected with atomic(savepoint=False).
This commit is contained in:
		| @@ -164,13 +164,6 @@ class Atomic(ContextDecorator): | ||||
|                     raise TransactionManagementError( | ||||
|                         "Your database backend doesn't behave properly when " | ||||
|                         "autocommit is off. Turn it on before using 'atomic'.") | ||||
|                 # When entering an atomic block with autocommit turned off, | ||||
|                 # Django should only use savepoints and shouldn't commit. | ||||
|                 # This requires at least a savepoint for the outermost block. | ||||
|                 if not self.savepoint: | ||||
|                     raise TransactionManagementError( | ||||
|                         "The outermost 'atomic' block cannot use " | ||||
|                         "savepoint = False when autocommit is off.") | ||||
|                 # Pretend we're already in an atomic block to bypass the code | ||||
|                 # that disables autocommit to enter a transaction, and make a | ||||
|                 # note to deal with this case in __exit__. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user