﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18816	"Remove ""trim"" argument from add_filter()"	Anssi Kääriäinen	nobody	"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."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	0	0	0	0	0	0
