#23589: Django 1.7 filter Q m2m bug
----------------------------------------------+--------------------
Reporter: Grafumbly | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
The behavior of Q objects has changed in an undocumented and breaking way
for m2m relationships in Django 1.7 from the behavior in 1.6.7, returning
different query results depending on the Django version.
In the case where you want to select a primary object that has related
objects of one type, but none of another, you could use a Q like this:
`q = Q(Q(relatedobject__someparam=True),
~Q(relatedobject__someparam=False))`
`results = PrimaryObject.objects.filter(q)`
Using this Q in a filter in 1.6.7 would give you all primary objects that
have relatedobjects with someparam=True and omit any primary objects that
also had a relatedobject with someparam=False. In 1.7 these objects are
returned despite the ~Q(relatedobject__someparam=False).
This gist provides a sample to illustrate the problem:
https://gist.github.com/scottsexton/375f7869839a98593695
--
Ticket URL: <https://code.djangoproject.com/ticket/23589>
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/052.2cca33c5f4efef7ce43354c25acd1863%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.