Opened 9 years ago

Last modified 7 years ago

#24254 closed Bug

Passing a query to "pk__in" of another query may result in invalid SQL — at Initial Version

Reported by: Torsten Bronger Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: bronger@…, Simon Charette Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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".

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top