Issue #8 new

Broken filter() on manager.

Łukasz Rekucki
created an issue

BaseEntityManager overrides {{{filter()}}} in a way that doesn't match Django's API. When filtering agains multi-value relatations (m2m, reverse FK manager), there is a differenct between {{{filter()}}} with two keyword arguments and chaining.

Your implementation turns {{{filter(x=,y=)}}} into {{{filter(x=).filter(y=)}}} which has a different meaning.

Comments (2)

  1. Andy Mikhailenko repo owner

    Thanks for the report.

    I haven't worked with Django ORM for a while so I don't see the semantic difference between the examples given. Could you please give a link to the documentation or describe the problem in your own words, possibly with examples in SQL?

    Also, any ideas about how to fix this?

  2. Łukasz Rekucki reporter

    Here's a link to the docs: In SQL terms, the first case is joining the table once and applying both filters, while chaining results in having a separate table for each filter.

    Creating a Q() object with all conditions and calling filter() once should fix the issue, but I haven't tested that (It also should be a lot faster, as calling filter() clones the whole QuerySet which is very slow for complex queries).

  3. Log in to comment