#29076: Model.refresh_from_db() should clear cached foreign key and one to one
fields
-------------------------------------+-------------------------------------
Reporter: Jon | Owner: nobody
Dufresne |
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 |
-------------------------------------+-------------------------------------
Currently, `Model.refresh_from_db()` doesn't clear cached foreign key or
one to one fields if the related ID has not changed. I find this behavior
counter intuitive and almost always undesired.
`Model.refresh_from_db()` is frequently used in testing. For the model to
be in an incompletely reloaded state can cause silent test passes or
unexpected test failures.
In my experience, this has behavior has also been a frequent pain point
for developers just learning the framework. Intuitively, most developers
think refreshing a model will refresh all attributes.
True, this behavior is documented. But I think it can be improved to more
often do the expected thing and help new Django developers.
A common use case:
A model instance with many fields relationships is altered by a view. A
test reloads the model to verify the instance changed as expected,
including the relationships.
--
Ticket URL: <https://code.djangoproject.com/ticket/29076>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.fe520ae23c30a34766c825115ba723ea%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.