Remove "trim" argument from add_filter()
|Reported by:||akaariai||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The sql.query.Query.split_exclude() needs to trim one final join when it adds filters to the original query. It does this by passing "trim" to add_filter(), and add_filter() then knows to trim the last join.
We can likely directly trim the last part of the join path in split_exclude() directly. This will remove the need to burden the add_filter() with the trim argument, and thus makes the ORM code easier to follow.
The patch in https://github.com/akaariai/django/tree/remove_trim is not commit ready. There are two problems in need of an answer:
- is the unconditional use of "pk__in" as the lookup in case there were just one lookup part in the path correct? It seems the pk would need to be changed to something else in case there is a to_field argument for the relation used.
- removing the trim argument from add_filter() will result in allow_m2m value being different when add_filter() is called from split_exclude().
For the above reasons: while tests pass with the above patch, I don't think it is correct.
The removal of trim arg would also maybe make it possible to remove the current trim_joins() altogether when combined with the patch from #10790, and this in turn would allow to change the return value from setup_joins() to something nicer. So, this is one more part in trying to clean the ORM.
Change History (3)
comment:1 Changed 20 months ago by akaariai
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset