#34099: update_or_create() not saving data assigned in a model's save() method
-------------------------------------+-------------------------------------
Reporter: Phil Gyford | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Release blocker | 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):
I would argue that this is the responsibility of the user to properly
account for `update_fields` when doing field assignments in a `save()`
override.
The issue is triggered by the change in the `update_or_create`
implementation but it's also broken when `update_fields` is used directly
{{{#!python
person = Person.objects.create(name="foo")
person.name = "bar"
person.save(update_fields={"name"}))
person.refresh_from_db()
assert person.nickname == "bar" # AssertionError
}}}
I feels like the `person.nickbar` assignment should also augment
`update_fields` if provided
{{{#!python
self.nickname = name
if update_fields is not None and "name" in update_fields:
update_fields = set(update_fields) | {"nickname"}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34099#comment:2>
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/01070183d8898b9c-4a5266c7-e222-414b-b737-8b256e0ffafd-000000%40eu-central-1.amazonses.com.