Opened 5 years ago

Closed 5 years ago

#30340 closed Bug (duplicate)

Filtering after `.difference()` does not work

Reported by: Herman S Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Example:

In [*]: User.objects.filter(
    ...:     id__in=[1,2,3,4],
    ...: ).difference(
    ...:     User.objects.filter(
    ...:         id__in=[1,2],
    ...:     )
    ...: ).values_list(
    ...:     'id', flat=True
    ...: ).filter(
    ...:     id=3,
    ...: )
Out[*]: <UserQuerySet [3, 4]>

The expected output from the query above is of course only [3,] and not [3,4]

Haven't tested this in 2.2.

Change History (1)

comment:1 by Tim Graham, 5 years ago

Component: UncategorizedDatabase layer (models, ORM)
Resolution: duplicate
Status: newclosed

Duplicate of #28519. The limitation is documented:

In addition, only LIMIT, OFFSET, COUNT(*), ORDER BY, and specifying columns (i.e. slicing, count(), order_by(), and values()/values_list()) are allowed on the resulting QuerySet. Further, databases place restrictions on what operations are allowed in the combined queries. For example, most databases don’t allow LIMIT or OFFSET in the combined queries.

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