mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #35044 -- Avoided clearing reverse relations and private fields when accessing deferred fields.
Regression ina7b5ad8b19for reverse relations and possibly in123b1d3fcffor private fields.
This commit is contained in:
committed by
Mariusz Felisiak
parent
74f7fe3f3d
commit
73df8b54a2
@@ -6,6 +6,7 @@ from .models import (
|
||||
Child,
|
||||
ChildProxy,
|
||||
Primary,
|
||||
PrimaryOneToOne,
|
||||
RefreshPrimaryProxy,
|
||||
Secondary,
|
||||
ShadowChild,
|
||||
@@ -326,3 +327,28 @@ class InvalidDeferTests(SimpleTestCase):
|
||||
)
|
||||
with self.assertRaisesMessage(FieldError, msg):
|
||||
Primary.objects.only("name").select_related("related")[0]
|
||||
|
||||
|
||||
class DeferredRelationTests(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.secondary = Secondary.objects.create(first="a", second="b")
|
||||
cls.primary = PrimaryOneToOne.objects.create(
|
||||
name="Bella", value="Baxter", related=cls.secondary
|
||||
)
|
||||
|
||||
def test_defer_not_clear_cached_relations(self):
|
||||
obj = Secondary.objects.defer("first").get(pk=self.secondary.pk)
|
||||
with self.assertNumQueries(1):
|
||||
obj.primary_o2o
|
||||
obj.first # Accessing a deferred field.
|
||||
with self.assertNumQueries(0):
|
||||
obj.primary_o2o
|
||||
|
||||
def test_only_not_clear_cached_relations(self):
|
||||
obj = Secondary.objects.only("first").get(pk=self.secondary.pk)
|
||||
with self.assertNumQueries(1):
|
||||
obj.primary_o2o
|
||||
obj.second # Accessing a deferred field.
|
||||
with self.assertNumQueries(0):
|
||||
obj.primary_o2o
|
||||
|
||||
Reference in New Issue
Block a user