Skip to content

Commit 71a3f26

Browse files
committed
concurrency.api.disable_concurrency is now a noop if applied to a model not under concurrency management
1 parent 128d5ac commit 71a3f26

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Release 1.1 (dev)
44
* add support for pypy
55
* new :class:`concurrency.fields.ConditionalVersionField`
66
* new decorator :class:`concurrency.api.concurrency_disable_increment`
7+
* :class:`concurrency.api.disable_concurrency` is now a noop if applied to a model not under concurrency management
8+
79

810
Release 1.0.1
911
-------------

docs/api.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ concurrency on any Model.
183183
This features has been developed to be used in django commands
184184

185185

186+
.. versionchanged:: 1.1
187+
188+
Does not raise an exception if a model not under concurrency management is passed as argument.
189+
186190
examples
187191
~~~~~~~~
188192

docs/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ How to run the tests
3939
4040
.. code-block:: bash
4141
42-
$ pip tox
42+
$ pip install tox
4343
$ tox
4444

src/concurrency/api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ class disable_concurrency(object):
114114
def __init__(self, model=None):
115115
self.model = model
116116
self.old_value = conf.ENABLED
117+
self.concurrency_managed = (model is None) or hasattr(model, '_concurrencymeta')
117118

118119
def __enter__(self):
120+
if not self.concurrency_managed:
121+
return
119122
if self.model is None:
120123
self.old_value, conf.ENABLED = conf.ENABLED, False
121124
elif isinstance(self.model, Model):
@@ -125,6 +128,8 @@ def __enter__(self):
125128
self.old_value, self.model._concurrencymeta.enabled = self.model._concurrencymeta.enabled, False
126129

127130
def __exit__(self, *args, **kwds):
131+
if not self.concurrency_managed:
132+
return
128133
if self.model is None:
129134
conf.ENABLED = self.old_value
130135
elif isinstance(self.model, Model):

0 commit comments

Comments
 (0)