[Django] #32095: update_or_create should utilize update_fields on update

18 views
Skip to first unread message

Django

unread,
Oct 9, 2020, 9:55:09 AM10/9/20
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
---------------------------------------------+------------------------
Reporter: Florian Apolloner | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
`update_or_create` should update only the fields in `default` on update,
not all fields. While it is concurrency-safe to update the whole model
since `update_or_create` fetches the object via `select_for_update` it is
still unnecessary to re transmit all fields back to the database (probably
results in more wal/binary logs written etc etc…).

In the end `update_or_create` (and most likely `get_or_create`) might be
written in more efficient ways depending on the database backend -- but
`update_fields` seems to be a rather low-hanging fruit.

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

Django

unread,
Oct 12, 2020, 12:22:00 AM10/12/20
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Florian
Type: | Apolloner
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(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
-------------------------------------+-------------------------------------
Changes (by felixxm):

* owner: Liel Fridman => Florian Apolloner
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/13526 PR]

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

Django

unread,
Oct 15, 2020, 6:36:37 AM10/15/20
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Florian
Type: | Apolloner
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:4>

Django

unread,
Sep 18, 2022, 3:28:30 PM9/18/22
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Sarah
Type: | Boyce

Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(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
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* owner: Florian Apolloner => Sarah Boyce
* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:5>

Django

unread,
Sep 19, 2022, 3:51:35 AM9/19/22
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Sarah
Type: | Boyce
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/16072 New PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:6>

Django

unread,
Sep 23, 2022, 5:46:10 AM9/23/22
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Sarah
Type: | Boyce
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(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
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 1 => 0


Comment:

Tentatively removing the `patch_needs_improvement` flag, there is a
comment about clarifying existing documentation but not sure if that needs
to be included in this PR :)

--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:7>

Django

unread,
Sep 24, 2022, 4:16:24 PM9/24/22
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Sarah
Type: | Boyce
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(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
-------------------------------------+-------------------------------------
Changes (by David Wobrock):

* cc: David Wobrock (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:8>

Django

unread,
Sep 25, 2022, 3:49:52 AM9/25/22
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Sarah
Type: | Boyce
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:9>

Django

unread,
Sep 25, 2022, 4:06:29 PM9/25/22
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Sarah
Type: | Boyce
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(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
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:10>

Django

unread,
Sep 29, 2022, 2:56:41 PM9/29/22
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Sarah
Type: | Boyce
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:11>

Django

unread,
Sep 30, 2022, 1:17:12 AM9/30/22
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Sarah
Type: | Boyce
Cleanup/optimization | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"6cc0f22a73970dd7c0d29d4d8d2ff9e1cc862b30" 6cc0f22a]:
{{{
#!CommitTicketReference repository=""
revision="6cc0f22a73970dd7c0d29d4d8d2ff9e1cc862b30"
Fixed #32095 -- Made QuerySet.update_or_create() save only fields passed
in defaults or with custom pre_save().

Thanks Florian Apolloner for the initial patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:13>

Django

unread,
Sep 30, 2022, 1:17:13 AM9/30/22
to django-...@googlegroups.com
#32095: update_or_create should utilize update_fields on update
-------------------------------------+-------------------------------------
Reporter: Florian Apolloner | Owner: Sarah
Type: | Boyce
Cleanup/optimization | Status: assigned

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"1d77b931f7df96ec4d6fa3835fe35547397cca1a" 1d77b93]:
{{{
#!CommitTicketReference repository=""
revision="1d77b931f7df96ec4d6fa3835fe35547397cca1a"
Refs #32095 -- Added model's Options._non_pk_concrete_field_names
property.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32095#comment:12>

Reply all
Reply to author
Forward
0 new messages