I'm reducing some Q objects (similar to what is described in ticket:32554.
Everything is fine for the case where the result is
`ExpressionWrapper(Q(pk__in=[]))`. However, when I reduce to
`ExpressionWrapper(~Q(pk__in=[]))` the query breaks.
== Symptoms
=== Working for `ExpressionWrapper(Q(pk__in=[]))`
{{{#!python
print(queryset.annotate(foo=ExpressionWrapper(Q(pk__in=[]),
output_field=BooleanField())).values("foo").query)
}}}
{{{#!sql
SELECT 0 AS "foo" FROM "agri_data_declaration"
}}}
=== Not working for `ExpressionWrapper(~Q(pk__in=[]))`
{{{#!python
print(declarations.annotate(foo=ExpressionWrapper(~Q(pk__in=[]),
output_field=BooleanField())).values("foo").query)
}}}
{{{#!sql
SELECT AS "foo" FROM "agri_data_declaration"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33374>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> == Problem Description
>
> I'm reducing some Q objects (similar to what is described in
> ticket:32554. Everything is fine for the case where the result is
> `ExpressionWrapper(Q(pk__in=[]))`. However, when I reduce to
> `ExpressionWrapper(~Q(pk__in=[]))` the query breaks.
>
> == Symptoms
>
> === Working for `ExpressionWrapper(Q(pk__in=[]))`
> {{{#!python
> print(queryset.annotate(foo=ExpressionWrapper(Q(pk__in=[]),
> output_field=BooleanField())).values("foo").query)
> }}}
>
> {{{#!sql
> SELECT 0 AS "foo" FROM "agri_data_declaration"
> }}}
>
> === Not working for `ExpressionWrapper(~Q(pk__in=[]))`
>
> {{{#!python
> print(declarations.annotate(foo=ExpressionWrapper(~Q(pk__in=[]),
> output_field=BooleanField())).values("foo").query)
> }}}
> {{{#!sql
> SELECT AS "foo" FROM "agri_data_declaration"
> }}}
New description:
== Problem Description
I'm reducing some Q objects (similar to what is described in ticket:32554.
Everything is fine for the case where the result is
`ExpressionWrapper(Q(pk__in=[]))`. However, when I reduce to
`ExpressionWrapper(~Q(pk__in=[]))` the query breaks.
== Symptoms
=== Working for `ExpressionWrapper(Q(pk__in=[]))`
{{{#!python
print(queryset.annotate(foo=ExpressionWrapper(Q(pk__in=[]),
output_field=BooleanField())).values("foo").query)
}}}
{{{#!sql
SELECT 0 AS "foo" FROM "agri_data_declaration"
}}}
=== Not working for `ExpressionWrapper(~Q(pk__in=[]))`
{{{#!python
print(queryset.annotate(foo=ExpressionWrapper(~Q(pk__in=[]),
output_field=BooleanField())).values("foo").query)
}}}
{{{#!sql
SELECT AS "foo" FROM "agri_data_declaration"
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:1>
Old description:
> == Problem Description
>
> I'm reducing some Q objects (similar to what is described in
> ticket:32554. Everything is fine for the case where the result is
> `ExpressionWrapper(Q(pk__in=[]))`. However, when I reduce to
> `ExpressionWrapper(~Q(pk__in=[]))` the query breaks.
>
> == Symptoms
>
> === Working for `ExpressionWrapper(Q(pk__in=[]))`
> {{{#!python
> print(queryset.annotate(foo=ExpressionWrapper(Q(pk__in=[]),
> output_field=BooleanField())).values("foo").query)
> }}}
>
> {{{#!sql
> SELECT 0 AS "foo" FROM "agri_data_declaration"
> }}}
>
> === Not working for `ExpressionWrapper(~Q(pk__in=[]))`
>
> {{{#!python
> print(queryset.annotate(foo=ExpressionWrapper(~Q(pk__in=[]),
> output_field=BooleanField())).values("foo").query)
> }}}
> {{{#!sql
> SELECT AS "foo" FROM "agri_data_declaration"
> }}}
New description:
== Problem Description
I'm reducing some Q objects (similar to what is described in ticket:32554.
Everything is fine for the case where the result is
`ExpressionWrapper(Q(pk__in=[]))`. However, when I reduce to
`ExpressionWrapper(~Q(pk__in=[]))` the query breaks.
== Symptoms
=== Working for `ExpressionWrapper(Q(pk__in=[]))`
{{{#!python
print(queryset.annotate(foo=ExpressionWrapper(Q(pk__in=[]),
output_field=BooleanField())).values("foo").query)
}}}
{{{#!sql
SELECT 0 AS "foo" FROM "table"
}}}
=== Not working for `ExpressionWrapper(~Q(pk__in=[]))`
{{{#!python
print(queryset.annotate(foo=ExpressionWrapper(~Q(pk__in=[]),
output_field=BooleanField())).values("foo").query)
}}}
{{{#!sql
SELECT AS "foo" FROM "table"
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:2>
* component: Uncategorized => Database layer (models, ORM)
* stage: Unreviewed => Accepted
Comment:
Good catch!
{{{#!python
>>> books =
Book.objects.annotate(selected=ExpressionWrapper(~Q(pk__in=[]),
output_field=BooleanField())).values('selected')
>>> list(books)
Traceback (most recent call last):
File "/django/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/django/django/db/backends/sqlite3/base.py", line 420, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: near "AS": syntax error
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:3>
* cc: David Wobrock (added)
* owner: nobody => David Wobrock
* has_patch: 0 => 1
* status: new => assigned
Comment:
Hi all,
Opened a PR to tackle this bug https://github.com/django/django/pull/15213
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:4>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:5>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"72b23c04d806adc8522fa9d10132e5c1d1011d5e" 72b23c04]:
{{{
#!CommitTicketReference repository=""
revision="72b23c04d806adc8522fa9d10132e5c1d1011d5e"
Fixed #33374 -- Fixed ExpressionWrapper annotations with full queryset.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:8>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"76e37513e22f4d9a01c7f15eee36fe44388e6670" 76e37513]:
{{{
#!CommitTicketReference repository=""
revision="76e37513e22f4d9a01c7f15eee36fe44388e6670"
Refs #33374 -- Adjusted full match condition handling.
Adjusting WhereNode.as_sql() to raise an exception when encoutering a
full match just like with empty matches ensures that all case are
explicitly handled.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:10>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"4b702c832cd550fe682ef37a69e93866815b9123" 4b702c8]:
{{{
#!CommitTicketReference repository=""
revision="4b702c832cd550fe682ef37a69e93866815b9123"
Refs #33374 -- Added tests for multi-table fast-deletion with filters that
match everything.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33374#comment:9>