Opened 6 years ago

Last modified 5 years ago

#29932 closed Bug

Queryset `difference()` after `intersection()` returns wrong queryset on SQLite — at Version 2

Reported by: michaeldel Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords: queryset sqlite difference intersection
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by michaeldel)

Considering a simple model

from django.db import models

class Foo(models.Model):
    pass

Here is the minimal way to encounter this issue

Foo.objects.create(pk=1)
Foo.objects.create(pk=2)

a = Foo.objects.all()
b = Foo.objects.intersection(Foo.objects.filter(pk=1))

assert a.count() == 2
assert b.count() == 1

diff = a.difference(b)

assert diff.exists()  # fails with SQLite!

This operation however works as expected on PostgreSQL.

Change History (2)

comment:1 by michaeldel, 6 years ago

Description: modified (diff)

comment:2 by michaeldel, 6 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top