#28344: Add for_update parameter to Model.refresh_from_db()
-------------------------------------+-------------------------------------
Reporter: Patryk Zawadzki | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Hugo Osvaldo Barrera):
I've had to deal with similar patterns many times (mostly, when avoiding
race conditions is critical -- for example, when closing and charging an
order).
However, I think I might prefer an alternative pattern for this; I'd very
much prefer if a model instance can lock it's own row. Currently, I've to
construct a single queryset like :
{{{
# Assume obj is a model instance:
MyModel.objects.filter(pk=obj.pk).select_for_update()
obj.some_attr = 13
obj.save()
}}}
A cleaner pattern for this sort of of thing would probably be something
like:
{{{
with obj.lock_for_update():
obj.some_attr = 13
# Would this be auto-saved at the end of the CM's block?
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.796926836b233911424f13fbaeec7fec%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.