1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #35044 -- Avoided clearing reverse relations and private fields when accessing deferred fields.

Regression in a7b5ad8b19 for reverse
relations and possibly in 123b1d3fcf for
private fields.
This commit is contained in:
Giannis Terzopoulos
2024-02-09 23:47:06 +01:00
committed by Mariusz Felisiak
parent 74f7fe3f3d
commit 73df8b54a2
4 changed files with 75 additions and 2 deletions

View File

@@ -740,12 +740,16 @@ class Model(AltersData, metaclass=ModelBase):
# Clear cached relations.
for field in self._meta.related_objects:
if field.is_cached(self):
if (fields is None or field.name in fields) and field.is_cached(self):
field.delete_cached_value(self)
# Clear cached private relations.
for field in self._meta.private_fields:
if field.is_relation and field.is_cached(self):
if (
(fields is None or field.name in fields)
and field.is_relation
and field.is_cached(self)
):
field.delete_cached_value(self)
self._state.db = db_instance._state.db