#34282: Optimize update_or_create when defaults is empty / False-y
-------------------------------------+-------------------------------------
Reporter: Timothy | Owner: Timothy Schilling
Schilling |
Type: | Status: assigned
Cleanup/optimization |
Component: Database | Version: dev
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 |
-------------------------------------+-------------------------------------
The defaults parameter to `update_or_create` is used to change the values
on a model instance after it's been fetched from the database. However,
it's not required to pass anything in through `defaults`. In these cases
where `defaults` is False-y, Django is performing an update on the model
instance that shouldn't be changing any values. Instead the call to
[object.save()](https://github.com/django/django/blob/stable/4.2.x/django/db/models/query.py#L971-L972)
should be skipped.
The concern would be needing to check for fields that use something like
`auto_now`.
--
Ticket URL: <https://code.djangoproject.com/ticket/34282>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070185da599c87-b7844dad-1c10-47bd-85dc-0ad829fb0f85-000000%40eu-central-1.amazonses.com.