#29476: Filter with BooleanField produces invalid SQL for .query
-------------------------------------+-------------------------------------
Reporter: Martin | Owner: nobody
Gropp |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hiho!
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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.2a579bdff322c1296f462fa3cbf6deca%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.