diff options
| author | Shai Berger <shai@platonix.com> | 2014-03-30 20:03:35 +0300 |
|---|---|---|
| committer | Shai Berger <shai@platonix.com> | 2014-04-10 01:44:30 +0300 |
| commit | 3a9a4570efc933a50efec27bdd06af11877eeac6 (patch) | |
| tree | a64bf01fe5d9bbe713f19c825ae85177f7b1d5cf /django | |
| parent | f6f188ffc7d48f7f38edea35234f23f2cfefda0b (diff) | |
[1.7.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
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/sql/compiler.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index e166492896..9351169357 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -11,6 +11,7 @@ from django.db.models.sql.constants import (CURSOR, SINGLE, MULTI, NO_RESULTS, 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 @@ -157,6 +158,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 |
