Handling race condition in model.save()

后端 未结 3 2000
时光取名叫无心
时光取名叫无心 2020-12-15 06:32

How should one handle a possible race condition in a model\'s save() method?

For example, the following example implements a model with an ordered list

3条回答
  •  一向
    一向 (楼主)
    2020-12-15 07:01

    I use Shawn Chin's solution and it proves very useful. The only change I did was to replace the

    self.position = self.parent.item_count
    

    with

    self.position = self.parent.latest('position').position
    

    just to make sure I am dealing with the latest position number (which in my case might not be item_count because of some reserved unused positions)

提交回复
热议问题