Skip to content

Commit

Permalink
add transaction management for select for update
Browse files Browse the repository at this point in the history
  • Loading branch information
michiya committed Aug 16, 2014
1 parent 906c0b7 commit 24f1d8e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sql_server/pyodbc/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from itertools import izip_longest as zip_longest

from django.db.models.sql import compiler
from django.db.transaction import TransactionManagementError
from django.utils import six

from sql_server.pyodbc.aggregates import AggregateWrapper
Expand Down Expand Up @@ -108,6 +109,9 @@ def as_sql(self, with_limits=True, with_col_aliases=False):
params.extend(f_params)

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
Expand Down

0 comments on commit 24f1d8e

Please sign in to comment.