[Django] #28344: Add `for_update=False` to `refresh_from_db()`

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #28344: Add `for_update=False` to `refresh_from_db()`

Django
#28344: Add `for_update=False` to `refresh_from_db()`
-------------------------------------+-------------------------------------
               Reporter:  Patryk     |          Owner:  nobody
  Zawadzki                           |
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Database   |        Version:  1.11
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I have a project where we deal with many financial operations that rely on
 transactions and row-level locking a lot to guard against race conditions.
 Unfortunately it's a common pattern for a function to accept an instance
 of model A, start an atomic block, fetch a new instance of the same row
 with `select_for_update()`, do a change, call `save()` and then refresh
 the original instance. It would all be easier if I could just call
 `instance.refresh_from_db(for_update=True)` and it would save a me a DB
 roundtrip to refresh the original instance passed (Django ORM does not
 have a session manager so the old object will not otherwise reflect the
 changes).

--
Ticket URL: <https://code.djangoproject.com/ticket/28344>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/049.d6dc498645b3c2336cfc01bfb0db8733%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db() (was: Add `for_update=False` to `refresh_from_db()`)

Django
#28344: Add for_update parameter to Model.refresh_from_db()
-------------------------------------+-------------------------------------
     Reporter:  Patryk Zawadzki      |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  1.11
  (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
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * stage:  Unreviewed => Accepted


Comment:

 Looks okay at first glance. Is the implementation fairly simple?

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:1>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.e6cd166a3e961a7b7d42c64508a982cf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#28344: Add for_update parameter to Model.refresh_from_db()
-------------------------------------+-------------------------------------
     Reporter:  Patryk Zawadzki      |                    Owner:  felixxm
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  1.11
  (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
-------------------------------------+-------------------------------------
Changes (by felixxm):

 * status:  new => assigned
 * owner:  nobody => felixxm


--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:2>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.f4c3482cb48151215d2bfddf2d712f5d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#28344: Add for_update parameter to Model.refresh_from_db()
-------------------------------------+-------------------------------------
     Reporter:  Patryk Zawadzki      |                    Owner:  felixxm
         Type:  New feature          |                   Status:  assigned
    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
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * version:  1.11 => master


Comment:

 Count me -0 on adding this given all the available `select_for_update()`
 options. 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.

 From my personal experience using `select_for_update()` with
 `refresh_from_db()` is not a common enough pattern to warrant the addition
 of this kwarg. Just me two cents.

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:3>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.0b80a4fade2e722a346801b06c8bd127%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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
-------------------------------------+-------------------------------------
Changes (by felixxm):

 * status:  assigned => new
 * owner:  felixxm => (none)


Comment:

 The basic implementation is fairly simple, but I also share concerns about
 full (with all options) support for `select_for_update()` with
 `refresh_from_db()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:4>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.09143019cd96e31c228dfdf0cf5ebb04%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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 Patryk Zawadzki):

 Would `refresh_for_update` make more sense? My case is really common in
 domains where resources are either shared or have to be protected from
 race conditions.

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:5>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.7df39705f05f7854180e7a11265a2917%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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 Patryk Zawadzki):

 I don't think a context manager would work as there is no way to
 ''unlock'' a row save for committing the transaction.

 Also would `self.lock_for_update()` be a `refresh_from_db` in disguise or
 would you prefer for it not to update the instance (potentially
 overwriting any unsaved changes)?

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:7>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.178390ec3298c0a14da5e421c8a0a4b5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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):

 If the transaction is written as I did in my example, you don't need to
 call `refresh_from_db`, since you only ever keep the reference to one
 loaded instance.

 I guess that saving when exiting the context manager would solve any
 doubts.

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:8>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.537328b3008fb423b620ae3c9164c68b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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 Patryk Zawadzki):

 Hugo, I appreciate your example but in my case I am dealing with financial
 transactions where I absolutely need to keep a database audit trail. This
 means I can't just wrap everything in a large transaction and risk it
 getting rolled back. Instead I have a number of tiny atomic blocks that
 need to be placed with surgical precision. This means I have to fetch the
 same object multiple times for it to act as the transaction
 synchronization point (via `SELECT FOR UPDATE` within each atomic block).

 Maybe it would be easier to introduce
 `transaction.atomic_with_locked(obj)` that would be the equivalent of:

 {{{
 with transaction.atomic():
     Foo.objects.select_for_update.get(pk=foo.pk)  # discarding the result
 is fine as the lock is now in place
     yield
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:9>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.feb8b54e89d76ec4096d09bb2675562c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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 adamhooper):

 @Patryk that code block you suggest has a bug.

 {{{
 foo = Foo.objects.get(id=1)  # loads entire record (call these _old_
 values)
 # Now, what happens here if somebody _else_ writes to foo?
 with transaction.atomic():
     Foo.objects.select_for_update.get(pk=foo.pk)  # selects and ignores
 _new_ values
     yield  # Modifies foo ... but foo.save() will save the _old_ values
 }}}

 I think this goes to show how necessary this feature is. Until it comes,
 I'll use this workaround:

 {{{
 foo = Foo.objects.get(id=1)
 with transaction.atomic():
     Foo.objects.select_for_update.get(pk=foo.pk)
     foo.reload_from_db()
     yield
 }}}

 ... which selects the row three times

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:10>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.117a7906af31fd697c8933da62218079%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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
-------------------------------------+-------------------------------------
Description changed by Jure Erznožnik:

Old description:

> I have a project where we deal with many financial operations that rely
> on transactions and row-level locking a lot to guard against race
> conditions. Unfortunately it's a common pattern for a function to accept
> an instance of model A, start an atomic block, fetch a new instance of
> the same row with `select_for_update()`, do a change, call `save()` and
> then refresh the original instance. It would all be easier if I could
> just call `instance.refresh_from_db(for_update=True)` and it would save a
> me a DB roundtrip to refresh the original instance passed (Django ORM
> does not have a session manager so the old object will not otherwise
> reflect the changes).
New description:

 I'm investigating this ticket for possible implementation at PyCon UK
 sprints. Initial thoughts:

 I like the pattern suggested above:

 {{{
 with obj.lock_for_update():
     obj.some_attr = 13
 # Would this be auto-saved at the end of the CM's block?
 }}}

 However, this one implies both a transaction and an auto-save to me. So my
 proposal would be to "decorate" the `lock_for_update()` with two
 parameters:

 * `atomic: bool=True`
 * `auto-save: bool=True`

 Would this be an acceptable solution?

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:11>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.8753b01a5e8f95b8d7a6029142bdb285%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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
-------------------------------------+-------------------------------------
Description changed by Jure Erznožnik:

Old description:

> I'm investigating this ticket for possible implementation at PyCon UK
> sprints. Initial thoughts:
>
> I like the pattern suggested above:
>
> {{{
> with obj.lock_for_update():
>     obj.some_attr = 13
> # Would this be auto-saved at the end of the CM's block?
> }}}
>
> However, this one implies both a transaction and an auto-save to me. So
> my proposal would be to "decorate" the `lock_for_update()` with two
> parameters:
>
> * `atomic: bool=True`
> * `auto-save: bool=True`
>
> Would this be an acceptable solution?
New description:



--

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:12>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.67f9454a2097c7fb8e8c4f3b69a85722%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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 Jure Erznožnik):

 I'm investigating this ticket for possible implementation at PyCon UK
 sprints. Initial thoughts:

 I like the pattern suggested above:

 {{{
 with obj.lock_for_update():
     obj.some_attr = 13
 # Would this be auto-saved at the end of the CM's block?
 }}}

 However, this one implies both a transaction and an auto-save to me. So my
 proposal would be to "decorate" the `lock_for_update()` with two
 parameters:

 * `atomic: bool=True`
 * `auto-save: bool=True`

 Would this be an acceptable solution?

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:13>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.65b20d09460cb7db2f868af69b6bc3ea%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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
-------------------------------------+-------------------------------------
Description changed by Jure Erznožnik:

Old description:



New description:

 I have a project where we deal with many financial operations that rely on
 transactions and row-level locking a lot to guard against race conditions.
 Unfortunately it's a common pattern for a function to accept an instance
 of model A, start an atomic block, fetch a new instance of the same row
 with `select_for_update()`, do a change, call `save()` and then refresh
 the original instance. It would all be easier if I could just call
 `instance.refresh_from_db(for_update=True)` and it would save a me a DB
 roundtrip to refresh the original instance passed (Django ORM does not
 have a session manager so the old object will not otherwise reflect the
 changes).

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:14>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.90f0449c97c0b89f03f5e003aaaf410d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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
-------------------------------------+-------------------------------------
Changes (by Raphael Michel):

 * cc: Raphael Michel (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:15>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.701520ddd86b5f4735a55b21133816a9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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
-------------------------------------+-------------------------------------
Changes (by Semyon Pupkov):

 * cc: Semyon Pupkov (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:16>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.703784c8d81e07ed1cdff9ce68fd1f76%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28344: Add for_update parameter to Model.refresh_from_db()

Django
In reply to this post by Django
#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
-------------------------------------+-------------------------------------
Changes (by Andrey Maslov):

 * cc: Andrey Maslov (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/28344#comment:17>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.199f1dfc4b2d6db0044b7039e905284f%40djangoproject.com.