I ran into this issue today on 1.11.13:
I am using `.filter` on a QuerySet to select all elements that have a
`BooleanField` set to true.
This works fine when run against the database, but the SQL produced by
`QuerySet.query` is incorrect.
Here's an example:
{{{
class Foo(Model):
bar = BooleanField()
query = str(Foo.objects.filter(bar=True).query)
}}}
Will produce SQL like this:
{{{
SELECT "table"."id", "table"."bar" FROM "table" WHERE "table"."bar" = True
}}}
This will not work, because `True` is interpreted as a column name.
(I was trying to use this SQL as part of a raw query, and ended up working
around the problem by replacing the `.filter` with another raw query
casting `bar` to integer in the `where`.)
Cheers
Martin
--
Ticket URL: <https://code.djangoproject.com/ticket/29476>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Comment:
As discussed in #17741, the `query` attribute isn't intended to give valid
SQL.
--
Ticket URL: <https://code.djangoproject.com/ticket/29476#comment:1>