mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.6.x] Fixed #22343 -- Disallowed select_for_update in autocommit mode
The ticket was originally about two failing tests, which are fixed by putting their queries in transactions. Thanks Tim Graham for the report, Aymeric Augustin for the fix, and Simon Charette, Tim Graham & Loïc Bistuer for review. Backport of b990df1d63 from master
This commit is contained in:
		| @@ -10,6 +10,7 @@ from django.db.models.sql.constants import (SINGLE, MULTI, ORDER_DIR, | ||||
| from django.db.models.sql.datastructures import EmptyResultSet | ||||
| from django.db.models.sql.expressions import SQLEvaluator | ||||
| from django.db.models.sql.query import get_order_dir, Query | ||||
| from django.db.transaction import TransactionManagementError | ||||
| from django.db.utils import DatabaseError | ||||
| from django.utils import six | ||||
| from django.utils.six.moves import zip | ||||
| @@ -142,6 +143,9 @@ class SQLCompiler(object): | ||||
|                 result.append('OFFSET %d' % self.query.low_mark) | ||||
|  | ||||
|         if self.query.select_for_update and self.connection.features.has_select_for_update: | ||||
|             if self.connection.get_autocommit(): | ||||
|                 raise TransactionManagementError("select_for_update cannot be used outside of a transaction.") | ||||
|  | ||||
|             # If we've been asked for a NOWAIT query but the backend does not support it, | ||||
|             # raise a DatabaseError otherwise we could get an unexpected deadlock. | ||||
|             nowait = self.query.select_for_update_nowait | ||||
|   | ||||
		Reference in New Issue
	
	Block a user