summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-12-28 23:16:13 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-12-28 23:35:08 +0100
commit5097d3c5faab2b6582c4cebee2b265fcdbb893eb (patch)
tree7ca9e4458d785ab0e30b0afcd07bea5ed39106c5 /django/db
parentbe4259004fd21ff5c78f02e9093a0786780e1c21 (diff)
[1.5.x] Fix #19524 -- Incorrect caching of parents of unsaved model instances.
Thanks qcwxezdas for the report. Refs #13839. Backport of e9c24be.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/models/base.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index bf9854d289..bd638e2499 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -583,6 +583,15 @@ class Model(six.with_metaclass(ModelBase, object)):
if field:
setattr(self, field.attname, self._get_pk_val(parent._meta))
+ # Since we didn't have an instance of the parent handy, we
+ # set attname directly, bypassing the descriptor.
+ # Invalidate the related object cache, in case it's been
+ # accidentally populated. A fresh instance will be
+ # re-built from the database if necessary.
+ cache_name = field.get_cache_name()
+ if hasattr(self, cache_name):
+ delattr(self, cache_name)
+
if meta.proxy:
return