#34227: Cyclic multi-level FilteredRelation with select_related() may set wrong
related object.
-------------------------------------+-------------------------------------
Reporter: zhu | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by zhu):
"cyclic" is not the case. Try the test below:
{{{
def test_wrong_select_related2(self):
with self.assertNumQueries(3):
p = list(
Tournament.objects.filter(id=self.t2.id).annotate(
style=FilteredRelation('pool__another_style'),
).select_related('style')
)
self.assertEqual(self.ps3, p[0].style)
self.assertEqual(self.p1, p[0].style.pool)
self.assertEqual(self.p3, p[0].style.another_pool)
}}}
result:
{{{
======================================================================
FAIL: test_wrong_select_related2
(known_related_objects.tests.ExistingRelatedInstancesTests.test_wrong_select_related2)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/repos/django/tests/known_related_objects/tests.py", line 186, in
test_wrong_select_related2
self.assertEqual(self.p3, p[0].style.another_pool)
AssertionError: <Pool: Pool object (3)> != <Tournament: Tournament object
(2)>
----------------------------------------------------------------------
}}}
The query fetch t2 and ps3, then call remote_setter('style', ps3, t2) and
local_setter(t2, ps3).
The joins is ['known_related_objects_tournament',
'known_related_objects_pool', 'style'].
The type of the first argument of the local_setter should be joins[-2],
but query do not fetch that object, so no available local_setter when
len(joins) > 2.
--
Ticket URL: <https://code.djangoproject.com/ticket/34227#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701855b91547e-2000663c-bcd3-4344-bb14-ccacc0174838-000000%40eu-central-1.amazonses.com.