Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a Django model object gets locked?

Is there any way to check if a Django model object is fetched using select_for_update()? Although 'locked' property in the following code does not exists actually, I want one like this.

with atomic():
   unlocked_obj = SomeModel.objects.get(pk=123)
   unlocked_obj.locked  # False

   locked_obj = SomeModel.objects.select_for_update().get(pk=123)
   locked_obj.locked  # True
like image 976
otsuka Avatar asked Sep 03 '14 15:09

otsuka


1 Answers

The only way to check that is by including "select_for_update(nowait = True)", if it is locked, Django raise a DatabaseError.

https://docs.djangoproject.com/en/1.11/ref/models/querysets/#select-for-update

like image 128
ALEXANDER GOMEZ HIGUITA Avatar answered Nov 07 '22 03:11

ALEXANDER GOMEZ HIGUITA