File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -512,6 +512,10 @@ def _update_initial_state(self):
512512 (field .attname , field .value_from_object (self )) for field in self .state_fields
513513 )
514514
515+ def refresh_from_db (self , * args , ** kwargs ):
516+ super (ConcurrentTransitionMixin , self ).refresh_from_db (* args , ** kwargs )
517+ self ._update_initial_state ()
518+
515519 def save (self , * args , ** kwargs ):
516520 super (ConcurrentTransitionMixin , self ).save (* args , ** kwargs )
517521 self ._update_initial_state ()
Original file line number Diff line number Diff line change 44
55
66class LockedBlogPost (ConcurrentTransitionMixin , models .Model ):
7- state = FSMField (default = 'new' , protected = True )
7+ state = FSMField (default = 'new' )
88 text = models .CharField (max_length = 50 )
99
1010 @transition (field = state , source = 'new' , target = 'published' )
@@ -60,7 +60,7 @@ def test_save_and_change_succeed(self):
6060
6161 post .delete ()
6262
63- def test_concurent_modifications_raise_exception (self ):
63+ def test_concurrent_modifications_raise_exception (self ):
6464 post1 = LockedBlogPost .objects .create ()
6565 post2 = LockedBlogPost .objects .get (pk = post1 .pk )
6666
@@ -86,3 +86,14 @@ def test_inheritance_crud_succeed(self):
8686 post = ExtendedBlogPost .objects .get (pk = post .pk )
8787 self .assertEqual ('rejected' , post .review_state )
8888 self .assertEqual ('test_inheritance_crud_succeed2' , post .text )
89+
90+ def test_concurrent_modifications_after_refresh_db_succeed (self ): # bug 255
91+ post1 = LockedBlogPost .objects .create ()
92+ post2 = LockedBlogPost .objects .get (pk = post1 .pk )
93+
94+ post1 .publish ()
95+ post1 .save ()
96+
97+ post2 .refresh_from_db ()
98+ post2 .remove ()
99+ post2 .save ()
You can’t perform that action at this time.
0 commit comments