mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #24418 -- Prevented crash in refresh_from_db with null fk
Thanks Johannes Lerch for the report, Tim Graham for the test case, and Simon Charette for the review.
This commit is contained in:
@@ -596,7 +596,7 @@ class Model(six.with_metaclass(ModelBase)):
|
||||
if field.rel and field.get_cache_name() in self.__dict__:
|
||||
rel_instance = getattr(self, field.get_cache_name())
|
||||
local_val = getattr(db_instance, field.attname)
|
||||
related_val = getattr(rel_instance, field.related_field.attname)
|
||||
related_val = None if rel_instance is None else getattr(rel_instance, field.related_field.attname)
|
||||
if local_val != related_val:
|
||||
del self.__dict__[field.get_cache_name()]
|
||||
self._state.db = db_instance._state.db
|
||||
|
||||
Reference in New Issue
Block a user