#25284: Regression when filtering by subquery
----------------------------------------------+--------------------
     Reporter:  Naddiseo                      |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  master
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 Consider the following:
 {{{#!python
 Model.objects.filter(related_id = RelatedModel.objects.all())
 }}}

 In django 1.8, the resulting query contains "related_id **IN** (SELECT id
 FROM ...)"
 In django 1.9, the "IN" is changed to an "=", which causes the query to
 break in MySql and Postgres.

 Is this an intentional change? If so, it needs to be documented as a
 breaking/backwards in-compatible change.

 Test case:
 {{{#!python

 class Egg(models.Model):
   class Meta:
     app_label = 'spam'
   value = models.IntegerField()

 class Spam(models.Model):
   class Meta:
     app_label = 'spam'
   egg = models.ForeignKey(Egg)

 class TestAssign(TestCase):
   def test_subquery(self):
     egg1 = Egg.objects.create(value=1)
     egg11 = Egg.objects.create(value=1)

     Spam.objects.create(egg=egg1)
     Spam.objects.create(egg=egg11)

     eggs1=Egg.objects.filter(value=1)
     q = Spam.objects.filter(egg__in=eggs1)
     self.assertEqual(2, len(list(q)))


 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25284>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.9179d391ddfa3d1e2dff05ac85ee1af3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to