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() == 1 # fails with SQLite!
}}}
This operation however works as expected on PostgreSQL.
--
Ticket URL: <https://code.djangoproject.com/ticket/29932>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> 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() == 1 # fails with SQLite!
> }}}
> This operation however works as expected on PostgreSQL.
New description:
Considering a simple model
{{{
#!python
from django.db import models
class Foo(models.Model):
pass
}}}
Here is the minimal way to encounter this issue
{{{
#!python
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() == 1 # fails with SQLite!
}}}
This operation however works as expected on PostgreSQL.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29932#comment:1>
Old description:
> Considering a simple model
> {{{
> #!python
> from django.db import models
>
> class Foo(models.Model):
> pass
> }}}
>
> Here is the minimal way to encounter this issue
> {{{
> #!python
> 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() == 1 # fails with SQLite!
> }}}
> This operation however works as expected on PostgreSQL.
New description:
Considering a simple model
{{{
#!python
from django.db import models
class Foo(models.Model):
pass
}}}
Here is the minimal way to encounter this issue
{{{
#!python
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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29932#comment:2>
* stage: Unreviewed => Accepted
Comment:
Reproduced at 413583e2e27af89e3ffaa4f8e34ee018fb77173c.
--
Ticket URL: <https://code.djangoproject.com/ticket/29932#comment:3>
* status: new => assigned
* owner: nobody => ChillarAnand
--
Ticket URL: <https://code.djangoproject.com/ticket/29932#comment:4>
* owner: ChillarAnand => felixxm
* has_patch: 0 => 1
Comment:
Wrapping compound queries in a parentheses solves this issue on Oracle. It
is more complicated on SQLite because compound queries do not support
parentheses on SQLite and I think that the only solution is to wrap them
in a subquery.
[https://github.com/django/django/pull/10715 PR]
@ChillarAnand I hope you don't mind that I assigned this ticket to myself.
--
Ticket URL: <https://code.djangoproject.com/ticket/29932#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"f9a33e3c3f4cfbff60522cd54455e78c96a9d2a4" f9a33e3c]:
{{{
#!CommitTicketReference repository=""
revision="f9a33e3c3f4cfbff60522cd54455e78c96a9d2a4"
Fixed #29932 -- Fixed combining compound queries with sub-compound queries
on SQLite and Oracle.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29932#comment:6>