#34603: ~Q() incorrectly interpreted as full rather than empty
-------------------------------------+-------------------------------------
Reporter: Anders | Owner: nobody
Kaseorg |
Type: Bug | Status: new
Component: Database | Version: 4.2
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 |
-------------------------------------+-------------------------------------
Since `Q()` is ([https://en.wikipedia.org/wiki/Empty_product#In_logic
correctly]) interpreted as matching every row, its negation `~Q()` should
be interpreted as matching no rows. However, Django incorrectly interprets
`~Q()` as matching every row like `Q()`.
{{{
>>> from django.db.models import Q
>>> from my_app.models import Client
>>> Client.objects.count()
12
>>> Client.objects.filter(Q()).count() # good, expected 12
12
>>> Client.objects.filter(~Q()).count() # bad, expected 0
12
}}}
Related: #5261, which introduced this incorrect behavior and added an
incorrect test for it.
--
Ticket URL: <https://code.djangoproject.com/ticket/34603>
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/010701886ad43823-ed27ec61-77e3-4c5d-8679-6784e7f0906f-000000%40eu-central-1.amazonses.com.