#32476: Django Query Generating Style Error
-------------------------------------+-------------------------------------
Reporter: thajones | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: Query, | Triage Stage:
Missing_Brackets | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* status: new => closed
* resolution: => invalid
Comment:
That's not an issue in the ORM but in your filters, you described the set
of rows that is always empty: `field1 IS NULL` and `field1 = ''` (which
implies that `field1 IS NOT NULL`). Also, wrapping conditions with the
same logical operator doesn't change anything, because
{{{
NOT (field1 != '' AND field1 IS NOT NULL and field1 IS NULL)
}}}
is equivalent to
{{{
NOT ((field1 != '' AND field1 IS NOT NULL) and field1 IS NULL)
}}}
You should use `.exclude(Q(field1__isnull=True) | Q(field1=''))`.
Please don't use Trac as a support channel in the future. Closing per
TicketClosingReasons/UseSupportChannels.
--
Ticket URL: <https://code.djangoproject.com/ticket/32476#comment:1>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.dc6900990b1968c2779c57e3455141b7%40djangoproject.com.