Opened 13 years ago

Closed 13 years ago

#17665 closed Bug (invalid)

Inconsitent behaviour of filter() with multi-valued relations.

Reported by: Łukasz Rekucki Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: krzysiumed@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Łukasz Rekucki)

This is probably a duplicate as I recall seeing a similar issue, but I couldn't find it, so here it goes:

We have 2 models (lets say, Company and Person), connected thru a M2M table (Membership) with additional attribute "active".

The following queries work as documented:

base = Company.objects.all()

# 1) select all companies in which person 1 is active
base.filter(membership_set__active=True, membership_set__person=1)

# 2) select all companies in which some membership is active or person '1' is a member
base.filter(membership_set__active=True).filter(membership_set__person=1)

But if you apply the filter() directly to the manager:

Company.objects.filter(membership_set__active=True, membership_set__person=1)

The behaviour is the same as query 2), while it should work like 1).

Change History (4)

comment:1 by Łukasz Rekucki, 13 years ago

Description: modified (diff)

comment:2 by Christopher Medrela, 13 years ago

I cannot reproduce it. Could you attach your models.py and example set of Company, Person and Membership_set objects please?

comment:3 by Christopher Medrela, 13 years ago

Cc: krzysiumed@… added

comment:4 by Łukasz Rekucki, 13 years ago

Resolution: invalid
Status: newclosed

Ugh, my bad for not testing this with a different set of model. Now that I did, it turns out to be fault of "eav-django" (https://bitbucket.org/neithere/eav-django/src/df6fac3e18be/eav/managers.py#cl-53), which redefines filter() on the manager (but not the QuerySet, wth?). Thanks for the sanity check and sorry for the noise.

Note: See TracTickets for help on using tickets.
Back to Top