#24254: Passing a query to "pk__in" of another query may result in invalid SQL
-------------------------------------+-------------------------------------
     Reporter:  bronger              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.7
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Old description:

> Consider the following models:
>
> {{{
> from django.db import models
>

> class Father(models.Model):
>     name = models.CharField(max_length=200)
>

> class Son(Father):
>
>     class Meta:
>         ordering = ("name",)
> }}}
>
> Then, the following query:
>
> {{{
> Son.objects.filter(pk__in=Son.objects.all().distinct()[:10])
> }}}
>
> results in an invalid SQL query.  SQLite complains with "only a single
> result allowed for a SELECT that is part of an expression".

New description:

 Consider the following model:

 {{{
 from django.db import models

 class MyModel(models.Model):
     name = models.CharField(max_length=200)

     class Meta:
         ordering = ("name",)
 }}}

 Then, the following query:

 {{{
 MyModel.objects.filter(pk__in=MyModel.objects.all().distinct()[:10])
 }}}

 results in an invalid SQL query.  SQLite complains with "only a single
 result allowed for a SELECT that is part of an expression".

--

Comment (by bronger):

 You're right, my example was not minimal.  I changed it so that only one
 model is defined.

--
Ticket URL: <https://code.djangoproject.com/ticket/24254#comment:2>
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/065.e9acd5d40d2837458e48fbffb401cb87%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to