diff options
| author | Paulo <commonzenpython@gmail.com> | 2017-10-29 12:01:04 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-10-30 14:02:03 -0400 |
| commit | fcfcf8aae470d893b0d2ef176434461edf9e9c4d (patch) | |
| tree | be88eadca0590238973412d0239542252f305c2d /django/db/models/fields/related_descriptors.py | |
| parent | f8946fbb5d7e8eb6c8ca7481b0cd4e78627ef8cf (diff) | |
Fixed #28742 -- Fixed AttributeError crash when assigning None to cached reverse relations.
Diffstat (limited to 'django/db/models/fields/related_descriptors.py')
| -rw-r--r-- | django/db/models/fields/related_descriptors.py | 11 |
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 fb3548f22e..5c6677155d 100644 --- a/django/db/models/fields/related_descriptors.py +++ b/django/db/models/fields/related_descriptors.py @@ -428,13 +428,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) |
