#30053: Allow for conditional QuerySet.update_or_create()
-------------------------------------+-------------------------------------
     Reporter:  Joshua Cannon        |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  QuerySet             |             Triage Stage:
  update_or_create                   |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Joshua Cannon:

Old description:

> {{{QuerySet.update_or_create()}}} is great since it lifts the burden of
> thread-safety and repeated code from the client. However there exists
> some scenarios where the "update" logic should be hidden behind a
> condition. (E.g. only update if the value of a {{{DateTimeField}}} is
> less than somevalue). There isn't much help for clients in these
> scenarios, with the best solution being to copy+paste
> {{{QuerySet.update_or_create()}}} and add a condition to the {{{if
> created:}}} expression.
>
> The condition would most likely be a callable that accepts one argument,
> the {{{got}}}ten instance.
>
> The solution should be trivial, either:
> A. Add a "condition" parameter to {{{update_or_create()}}} (along with
> logic to make the feature backwards compatible, likely checking if the
> value is callable with one argument or not, since "condition" could be a
> field)
> B. Add another method, and re-write {{{update_or_create()}}} in terms of
> the new method with a condition that is always true.

New description:

 {{{QuerySet.update_or_create()}}} is great since it lifts the burden of
 thread-safety and repeated code from the client. However there exists some
 scenarios where the "update" logic should be hidden behind a condition.
 (E.g. only update if the value of a {{{DateTimeField}}} is less than some
 value). There isn't much help for clients in these scenarios, with the
 best solution being to copy+paste {{{QuerySet.update_or_create()}}} and
 add a condition to the {{{if created:}}} expression.

 The condition would most likely be a callable that accepts one argument,
 the {{{got}}}ten instance.

 The solution should be trivial, either:
 A. Add a "condition" parameter to {{{update_or_create()}}} (along with
 logic to make the feature backwards compatible, likely checking if the
 value is callable with one argument or not, since "condition" could be a
 field)
 B. Add another method, and re-write {{{update_or_create()}}} in terms of
 the new method with a condition that is always true.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30053#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 [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/068.a7b7b07acb1bbe78286589cb778d4e4a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to