#16609: Admin searches produce duplicate results if search_fields contains M2M traversals -------------------------------------+------------------------------------- Reporter: | Owner: nobody cheater00@… | Status: new Type: Bug | Component: contrib.admin Milestone: | Severity: Normal Version: SVN | Keywords: search_fields m2m Resolution: | duplicate duplicates Triage Stage: | Has patch: 0 Unreviewed | Needs tests: 0 Needs documentation: 0 | Easy pickings: 0 Patch needs improvement: 0 | UI/UX: 0 | -------------------------------------+-------------------------------------
Old description: > I believe this has already been touched upon in #15819, however the > consensus (comment ticket:15819#comment:13) was > > "For people in situations where .distinct() is broken for whatever > reason, the workaround here is simple: don't use search_fields with > relations in a way that triggers it." > > I couldn't find a ticket for this, so here it is. > > In my case, I am searching for a keyword which is found in a > search_fields item that isn't traversing M2M. When search_fields also > contains a M2M traversal, I get duplicate results. > > In my case - this might be relevant or not - I am traversing a ForeignKey > first and then an M2M field in that problematic search_fields entry, e.g: > > search_fields = ['=id', '=fkmodel__m2mmodel__name'] > > This happens even though the string is not matched by > fkmodel__m2mmodel__name, only by id. > > This might not be clear, this is what the model relations look like: > > (Model SearchedModel) --ForeignKey--> (Model FKModel) --ManyToMany--> > (Model M2MModel) > > M2MModel contains the name field that I have specified in search_fields. > > This might or might not be related to #15559. > > I have tested this against 1.3, yesterday's 1.3.X, and yesterday's dev > and it is broken in all of them. (today is 10 Aug 2011) New description: I believe this has already been touched upon in #15819, however the consensus (comment ticket:15819#comment:13) was "For people in situations where .distinct() is broken for whatever reason, the workaround here is simple: don't use search_fields with relations in a way that triggers it." I couldn't find a ticket for this, so here it is. In my case, I am searching for a keyword which is found in a search_fields item that isn't traversing M2M. When search_fields also contains a M2M traversal, I get duplicate results. In my case - this might be relevant or not - I am traversing a ForeignKey first and then an M2M field in that problematic search_fields entry, e.g: {{{ search_fields = ['=id', '=fkmodel__m2mmodel__name'] }}} This happens even though the string is not matched by fkmodel__m2mmodel__name, only by id. This might not be clear, this is what the model relations look like: {{{ (Model SearchedModel) --ForeignKey--> (Model FKModel) --ManyToMany--> (Model M2MModel) }}} M2MModel contains the name field that I have specified in search_fields. This might or might not be related to #15559. I have tested this against 1.3, yesterday's 1.3.X, and yesterday's dev and it is broken in all of them. (today is 10 Aug 2011) -- Comment (by aaugustin): Fixed formatting. -- Ticket URL: <https://code.djangoproject.com/ticket/16609#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.