1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[1.9.x] Fixed #25715 -- Fixed Model.refresh_from_db() with ForeignKey w/on_delete=SET_NULL.

Backport of 54e2e688e1 from master
This commit is contained in:
Tim Graham
2015-11-20 10:31:33 -05:00
parent 0adbac4943
commit 8727dc8e95
4 changed files with 16 additions and 1 deletions

View File

@@ -593,7 +593,7 @@ class Model(six.with_metaclass(ModelBase)):
rel_instance = getattr(self, field.get_cache_name())
local_val = getattr(db_instance, field.attname)
related_val = None if rel_instance is None else getattr(rel_instance, field.target_field.attname)
if local_val != related_val:
if local_val != related_val or (local_val is None and related_val is None):
del self.__dict__[field.get_cache_name()]
self._state.db = db_instance._state.db