Re: [Django] #34996: Enhance update_or_create() method with upsert SQL. (was: Enhance update_or_create method with upsert sql)

6 views
Skip to first unread message

Django

unread,
Nov 26, 2023, 11:48:11 PM11/26/23
to django-...@googlegroups.com
#34996: Enhance update_or_create() method with upsert SQL.
-------------------------------------+-------------------------------------
Reporter: Jordan Bae | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* type: Cleanup/optimization => New feature
* resolution: => wontfix


Comment:

Thanks for this ticket, however, this change would be backward
incompatible as `get_or_create()` is
[https://docs.djangoproject.com/en/stable/ref/models/querysets/#update-or-
create documented] to be a shortcut for the pattern:
{{{#!python
try:
<<get>>
<<save>>
except DoesNotExist:
<<update>>
}}}
With your proposition `save()` would not be called anymore (and folks have
a custom logic in their `save()` methods). Moreover support for "UPSERT"
varies in databases, and it's already possible to do this with passing a
single object to the `bulk_create()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/34996#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages