mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #29896 -- Fixed incorrect Model.save() cache relation clearing for foreign keys that use to_field.
Regression in ee49306176.
This commit is contained in:
@@ -676,9 +676,9 @@ class Model(metaclass=ModelBase):
|
||||
"save() prohibited to prevent data loss due to "
|
||||
"unsaved related object '%s'." % field.name
|
||||
)
|
||||
# If the relationship's pk was changed, clear the cached
|
||||
# relationship.
|
||||
if obj and obj.pk != getattr(self, field.attname):
|
||||
# If the relationship's pk/to_field was changed, clear the
|
||||
# cached relationship.
|
||||
if obj and getattr(obj, field.target_field.attname) != getattr(self, field.attname):
|
||||
field.delete_cached_value(self)
|
||||
|
||||
using = using or router.db_for_write(self.__class__, instance=self)
|
||||
|
||||
Reference in New Issue
Block a user