Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Rename ConcurrentUpdate to ConcurrentTransition
Browse files Browse the repository at this point in the history
ConcurrentUpdate is too generic - one might get a feeling that
it catches all concurrent updates (like optimistic lock does),
when in fact it only catches concurrent state transitions.
  • Loading branch information
knaperek committed Jul 9, 2014
1 parent 1dc1b30 commit a76824d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions django_fsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django_fsm.signals import pre_transition, post_transition


__all__ = ['TransitionNotAllowed', 'ConcurrentUpdate',
__all__ = ['TransitionNotAllowed', 'ConcurrentTransition',
'FSMFieldMixin', 'FSMField', 'FSMIntegerField',
'FSMKeyField', 'FSMLockMixin', 'transition',
'can_proceed', 'has_transition_perm']
Expand All @@ -33,7 +33,7 @@ class TransitionNotAllowed(Exception):
"""Raised when a transition is not allowed"""


class ConcurrentUpdate(Exception):
class ConcurrentTransition(Exception):
"""
Raised when the transition cannot be executed because the
object has become stale (state has been changed since it
Expand Down Expand Up @@ -350,7 +350,7 @@ class FSMLockMixin(object):
Instance of a model based on this Mixin will be prevented from saving into DB if any
of its state fields (instances of FSMFieldMixin) has been changed since the object
was fetched from the database. *ConcurrentUpdate* exception will be raised in such
was fetched from the database. *ConcurrentTransition* exception will be raised in such
cases.
For guaranteed protection against such race conditions, make sure:
Expand Down Expand Up @@ -399,7 +399,7 @@ def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_updat
# Thus, we need to make sure we only catch the case when the object *is* in the DB, but with changed state; and
# mimic standard _do_update behavior otherwise. Django will pick it up and execute _do_insert.
if not updated and base_qs.filter(pk=pk_val).exists():
raise ConcurrentUpdate("Cannot save object! The state has been changed since fetched from the database!")
raise ConcurrentTransition("Cannot save object! The state has been changed since fetched from the database!")

return updated

Expand Down
4 changes: 2 additions & 2 deletions tests/testapp/tests/test_lock_mixin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django.test import TestCase
from django_fsm import FSMField, FSMLockMixin, ConcurrentUpdate, transition
from django_fsm import FSMField, FSMLockMixin, ConcurrentTransition, transition


class LockedBlogPost(FSMLockMixin, models.Model):
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_concurent_modifications_raise_exception(self):

post2.text = 'aaa'
post2.publish()
with self.assertRaises(ConcurrentUpdate):
with self.assertRaises(ConcurrentTransition):
post2.save()

def test_inheritance_crud_succeed(self):
Expand Down

0 comments on commit a76824d

Please sign in to comment.