[Django] #25195: update_or_create doesn't understand F() operations

82 views
Skip to first unread message

Django

unread,
Jul 30, 2015, 4:58:37 AM7/30/15
to django-...@googlegroups.com
#25195: update_or_create doesn't understand F() operations
-------------------------------------+-------------------------------------
Reporter: mjtamlyn | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version: master
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 |
-------------------------------------+-------------------------------------
This may not be possible to resolve, but it would be really nice if you
could do something like
{{{
Foo.objects.update_or_create(name='bar', defaults={'value': F('value') +
1})
}}}

This would only be possible when value has a default, and we would need to
resolve the F() object to the default. It may be that we need a different
object which resolves to an expression when used in an update but resolves
differently when used in a create.

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

Django

unread,
Jul 30, 2015, 7:23:52 AM7/30/15
to django-...@googlegroups.com
#25195: update_or_create doesn't understand F() operations
-------------------------------------+-------------------------------------
Reporter: mjtamlyn | Owner: nobody
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 timgraham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25195#comment:1>

Django

unread,
Aug 24, 2018, 5:24:17 PM8/24/18
to django-...@googlegroups.com
#25195: update_or_create doesn't understand F() operations
-------------------------------------+-------------------------------------
Reporter: Marc Tamlyn | Owner: nobody

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 ghazpar):

How about the following?

{{{
Foo.objects.update_or_create(name='bar', defaults={'value':

Coalesce('value', 0) + 1})
}}}

where one could specify an explicit default?

--
Ticket URL: <https://code.djangoproject.com/ticket/25195#comment:2>

Django

unread,
Aug 27, 2018, 9:23:36 PM8/27/18
to django-...@googlegroups.com
#25195: update_or_create doesn't understand F() operations
-------------------------------------+-------------------------------------
Reporter: Marc Tamlyn | Owner: nobody
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 Simon Charette):

Replying to [comment:2 Marc Parizeau]:
> How about the following?


>
> {{{
> Foo.objects.update_or_create(name='bar', defaults={'value':

Coalesce('value', 0) + 1})
> }}}
>
> where one could specify an explicit default?

We'd need to special case `Coalesce` in `update_or_create` for this to
work as references to columns are not allowed in `INSERT`s.

--
Ticket URL: <https://code.djangoproject.com/ticket/25195#comment:3>

Django

unread,
Mar 12, 2024, 4:52:40 AM3/12/24
to django-...@googlegroups.com
#25195: update_or_create doesn't understand F() operations
-------------------------------------+-------------------------------------
Reporter: Marc Tamlyn | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: dev
(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 Ülgen Sarıkavak):

* cc: Ülgen Sarıkavak (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/25195#comment:4>
Reply all
Reply to author
Forward
0 new messages