summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorPaulo <commonzenpython@gmail.com>2017-10-29 12:01:04 +0100
committerTim Graham <timograham@gmail.com>2017-10-30 14:25:34 -0400
commitf2d5417d3b7a4012298fcffc6eab618cc09d0344 (patch)
tree4871af703a282a7c05d0f4834802faf087afd958 /django
parent1f4e9935ef2bfb919cd05ab1a24cf2191048c3d8 (diff)
[2.0.x] Fixed #28742 -- Fixed AttributeError crash when assigning None to cached reverse relations.
Backport of fcfcf8aae470d893b0d2ef176434461edf9e9c4d from master
Diffstat (limited to 'django')
-rw-r--r--django/db/models/fields/related_descriptors.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py
index 39d7223d8a..1cce498d3d 100644
--- a/django/db/models/fields/related_descriptors.py
+++ b/django/db/models/fields/related_descriptors.py
@@ -410,13 +410,10 @@ class ReverseOneToOneDescriptor:
if value is None:
# Update the cached related instance (if any) & clear the cache.
- try:
- # Following the example above, this would be the cached
- # ``restaurant`` instance (if any).
- rel_obj = self.related.get_cached_value(instance)
- except KeyError:
- pass
- else:
+ # Following the example above, this would be the cached
+ # ``restaurant`` instance (if any).
+ rel_obj = self.related.get_cached_value(instance, default=None)
+ if rel_obj is not None:
# Remove the ``restaurant`` instance from the ``place``
# instance cache.
self.related.delete_cached_value(instance)