mirror of
https://github.com/django/django.git
synced 2025-01-18 14:24:39 +00:00
Refs #34925 -- Avoided altering passed by reference refresh_from_db(fields).
Follow up to b0ec87b8578147be4357c90eabcd2b916c780810.
This commit is contained in:
parent
b0ec87b857
commit
978680db22
@ -691,6 +691,7 @@ class Model(AltersData, metaclass=ModelBase):
|
|||||||
self._prefetched_objects_cache = {}
|
self._prefetched_objects_cache = {}
|
||||||
else:
|
else:
|
||||||
prefetched_objects_cache = getattr(self, "_prefetched_objects_cache", ())
|
prefetched_objects_cache = getattr(self, "_prefetched_objects_cache", ())
|
||||||
|
fields = list(fields)
|
||||||
for field in list(fields):
|
for field in list(fields):
|
||||||
if field in prefetched_objects_cache:
|
if field in prefetched_objects_cache:
|
||||||
del prefetched_objects_cache[field]
|
del prefetched_objects_cache[field]
|
||||||
@ -711,7 +712,6 @@ class Model(AltersData, metaclass=ModelBase):
|
|||||||
# Use provided fields, if not set then reload all non-deferred fields.
|
# Use provided fields, if not set then reload all non-deferred fields.
|
||||||
deferred_fields = self.get_deferred_fields()
|
deferred_fields = self.get_deferred_fields()
|
||||||
if fields is not None:
|
if fields is not None:
|
||||||
fields = list(fields)
|
|
||||||
db_instance_qs = db_instance_qs.only(*fields)
|
db_instance_qs = db_instance_qs.only(*fields)
|
||||||
elif deferred_fields:
|
elif deferred_fields:
|
||||||
fields = [
|
fields = [
|
||||||
|
@ -951,7 +951,9 @@ class ModelRefreshTests(TestCase):
|
|||||||
# Relation is added and prefetch cache is stale.
|
# Relation is added and prefetch cache is stale.
|
||||||
self.assertCountEqual(a2_prefetched.selfref_set.all(), [])
|
self.assertCountEqual(a2_prefetched.selfref_set.all(), [])
|
||||||
self.assertCountEqual(a2_prefetched.cited.all(), [])
|
self.assertCountEqual(a2_prefetched.cited.all(), [])
|
||||||
a2_prefetched.refresh_from_db(fields=["selfref_set", "cited"])
|
fields = ["selfref_set", "cited"]
|
||||||
|
a2_prefetched.refresh_from_db(fields=fields)
|
||||||
|
self.assertEqual(fields, ["selfref_set", "cited"])
|
||||||
# Cache was cleared and new results are available.
|
# Cache was cleared and new results are available.
|
||||||
self.assertCountEqual(a2_prefetched.selfref_set.all(), [s])
|
self.assertCountEqual(a2_prefetched.selfref_set.all(), [s])
|
||||||
self.assertCountEqual(a2_prefetched.cited.all(), [s])
|
self.assertCountEqual(a2_prefetched.cited.all(), [s])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user