#28344: Add for_update parameter to Model.refresh_from_db()
-------------------------------------+-------------------------------------
     Reporter:  Patryk Zawadzki      |                    Owner:  (none)
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Aivars Kalvāns):

 Replying to [comment:3 Simon Charette]:
 > I fear we might open a can of worms here and have to either say no to
 `nowait`, `skip_locked` and now `of` support in the future or allow
 `for_update` to be a dict delegating kwargs to the underlying
 `select_for_update()` call.

 I think most of those parameters do not apply to operations on the
 specific model:

 `of` when multiple models have to be locked, a QuerySet should be the
 right choice

 `skip_locked` does not make sense when working with one specific instance
 of Model (primary key)

 `nowait` might be interesting - something similar to
 `threading.Lock.acquire(blocking=False)`. But unlike `acquire` which
 returns a boolean, `select_for_update` raises `DatabaseError`. Raising an
 exception from `refresh_from_db` would suggest the object is in an invalid
 state. Code that uses the object after the exception would raise eyebrows
 during code review. Making `refresh_from_db` return a boolean indicating
 if it succeeded or not could also lead to issues because people are not
 used to checking the result of `refresh_from_db`.

 So I think the default `select_for_update` is the only right solution.
 Adding `nowait` might be an option together with a new dedicated method
 `refresh_for_update` but I haven't seen use for that in my domain.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:25>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018c5569d8da-57a6368c-4262-4185-bb38-87ecd19b1fa3-000000%40eu-central-1.amazonses.com.

Reply via email to