#20939 closed Cleanup/optimization (fixed)
Convert QuerySet to Query when filtering
Reported by: | Anssi Kääriäinen | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The current ORM coding has very similar, yet not equivalent paths for using QuerySet and the internal Query when doing filter(something=queryset_or_query). It seems that converting a QuerySet to Query early on would lead to cleaner implementation. Proof of concept here: https://github.com/akaariai/django/tree/queryset_to_query_in_filter
There are two problems in the current implementation:
- The way user-defined .values() and Django issued .values() in build_filter() is detected is ugly
- There is no multidb protection (test_subquery in multiple_database.tests.QueryTestCase) fails).
I'll mark this as accepted directly in the sense of "worth doing if above problems can be addressed).
Note:
See TracTickets
for help on using tickets.
I rebased and updated this to see if it's still worth doing and to learn something in the process. It's still incomplete and tests aren't passing: PR.