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.
* owner: nobody => zhu
* status: new => assigned
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/16408
--
Ticket URL: <https://code.djangoproject.com/ticket/34227#comment:4>