django
django copied to clipboard
Fixed #36385 -- Simplified filtering in QuerySet.
Trac ticket number
ticket-36385
Branch description
Some of the code for filtering QuerySet is overly complex which makes it hard to follow:
- Methods that are nearly identical, e.g.
QuerySet._clone()vsQuerySet._chain()andQuery.clone()vsQuery.chain() - Private API like
Queryset.complex_filter()which exists for a specific case but can be handled using public APIs - Flags such as
_defer_next_filterand_sticky_filterthat affect the next call toQuerySet.filter() - Passing around deconstructed pieces instead of building a
Q()as early as possible - Not using the
klassargument toQuery.chain()
I had hoped to eliminate Query.filter_is_sticky and pass the used_aliases to Query.add_q(), but I think that's a non-starter as it has to apply after the next clone. (Hard to get my head around it!)
Checklist
- [x] This PR targets the
mainbranch. - [x] The commit message is written in past tense, mentions the ticket number, and ends with a period.
- [x] I have checked the "Has patch" ticket flag in the Trac system.
- [x] I have added or updated relevant tests.
- [x] I have added or updated relevant docs, including release notes if applicable.
- [x] I have attached screenshots in both light and dark modes for any UI changes.