Keep in mind that filter(or_queries[0] & or_queries[1] & ... & or_queries[n]) can generate different results from filter(or_queries[0]).filter(or_queries[1]).filter(...).filter(or_queries[n]) if any of filters spans multi-valued relationships.
For example, given models Book and Author and a AuthorAmin searching both books__title and books__description your solution could filter out results that use to be displayed as search terms will have to be present in both Book.title and Book.description to match.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/9c504356-1efa-4a9b-84e7-a613940f4255%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi list,
I came to suggest a resolution for the above: the potential for impossible (or resource-gobbling) queries in admin changelist searches. (Ticket)
Several folks have proposed the same solution: AND’ing Q objects together rather than chaining filters. Last time we had a PR, the author was pointed here (hi OP!) in light of the subtle behavior change that would crop up in searches over multi-valued relationships. We would be moving from the second example query in "spanning multi-valued relationships" to the first example query, which will return fewer rows.
I see three +1s above in this thread. I write to add:
1 — I think this is an implementation detail. The admin changelist docs do not specify which of the two documented patterns for filtering multivalued relationships is used.
2 — Intuition is ambiguous here. I’m sure there could be convincing examples for each query pattern. That leads me to say it’s better for the problematic behavior to be opt-in. If folks really want the old behavior they can customize and then impose some limits to prevent excessive joins.
New PR with tests. Came here to summarize the state of play before opening a substantially similar PR to OP’s. Thoughts, input, desires all welcomed.
Cheers,
Jacob
PS — there is another accepted ticket for the same root cause framed as a request to just limit the number of terms in admin changelist searches. I think we could wontfix it if we instead address the root cause.
If folks really want the old behavior they can customize and then impose some limits to prevent excessive joins.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/99bee4d2-4e3f-4c20-9ae0-f2b71b04e08an%40googlegroups.com.