--
Ticket URL: <https://code.djangoproject.com/ticket/34226>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => needsinfo
* component: Uncategorized => Database layer (models, ORM)
Comment:
Replying to [ticket:34226 zhu]:
> should use partial, just like the remote_setter
Why? it doesn't use a `name` values from the loop. I don't think you've
explained the issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:1>
Comment (by Mariusz Felisiak):
Replying to [comment:1 Mariusz Felisiak]:
> Why? it doesn't use a `name` values from the loop. I don't think you've
explained the issue.
Ahh, OK, it uses `f`. Can you provide a regression test?
--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:2>
* type: Uncategorized => Bug
--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:3>
* cc: Simon Charette, Hasan Ramezani (added)
* status: closed => new
* resolution: needsinfo =>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:4>
Comment (by zhu):
Replying to [comment:2 Mariusz Felisiak]:
> Replying to [comment:1 Mariusz Felisiak]:
>
> > Why? it doesn't use a `name` values from the loop. I don't think
you've explained the issue.
>
> Ahh, OK, it uses `f`. Can you provide a regression test?
{{{#!python
# models.py
from django.db import models
class Pool(models.Model):
name = models.CharField(max_length=30)
class AnotherPoolStyle(models.Model):
name = models.CharField(max_length=30)
pool1 = models.OneToOneField(Pool, models.CASCADE,
related_name='style_from_pool1')
pool2 = models.OneToOneField(Pool, models.CASCADE,
related_name='style_from_pool2')
# tests.py
from django.test import TestCase
from django.db.models import FilteredRelation
class Tests(TestCase):
@classmethod
def setUpTestData(cls):
cls.p1 = Pool.objects.create(name="pool1")
cls.p2 = Pool.objects.create(name="pool2")
cls.ap = AnotherPoolStyle.objects.create(
name="Another Pool Style",
pool1=cls.p1,
pool2=cls.p2,
)
def test_filtered_relation_select_related(self):
with self.assertNumQueries(1):
ps = list(AnotherPoolStyle.objects.annotate(
p1=FilteredRelation('pool1'),
p2=FilteredRelation('pool2'),
).select_related('p1', 'p2'))
self.assertIs(ps[0], ps[0].p1.style_from_pool1) # failed
self.assertIs(ps[0], ps[0].p2.style_from_pool2)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34226#comment:5>