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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With