#34226: The local_setter may use a wrong f
-------------------------------------+-------------------------------------
     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):

 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>
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/010701853e656c55-9075a980-6e54-4785-895c-9f39614b73e4-000000%40eu-central-1.amazonses.com.

Reply via email to