diff options
| author | Paulo <commonzenpython@gmail.com> | 2017-09-20 23:27:04 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-11-09 11:40:34 -0500 |
| commit | ee49306176a2d2f1751cb890bd607d42c7c09196 (patch) | |
| tree | f79ff9ba8642a33f0720f6ac0ff684e038367091 /django | |
| parent | ebb998976e2889c669972ed3d1b372cc6a2b5229 (diff) | |
Fixed #27710 -- Made Model.save() invalidate cached, stale relations after a primary key assignment.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/base.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index e8ef2db913..3f4d65571d 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -674,6 +674,10 @@ class Model(metaclass=ModelBase): "save() prohibited to prevent data loss due to " "unsaved related object '%s'." % field.name ) + # If the relationship's pk was changed, clear the cached + # relationship. + if obj and obj.pk != getattr(self, field.attname): + field.delete_cached_value(self) using = using or router.db_for_write(self.__class__, instance=self) if force_insert and (force_update or update_fields): |
