Opened 6 years ago

Closed 6 years ago

#20991 closed Bug (duplicate)

[Regression] Admin searches should use distinct, if query involves joins.

Reported by: iorlas Owned by: nobody
Component: contrib.admin Version: 1.5
Severity: Normal Keywords: admin, regression, distinct
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

As we can see, in #2818 we have fixed bug in django admin behavior with joins - we should use distinct in this cases. Commit 4938c8e fixed this issue.
But, in a89b156 it was reworked as set of codelines for enhanced conditions. To check for possible joins, was created function lookup_needs_distinct. It looks for field by name(for example, in 'userdocsname' it takes 'user') and does some checks to verify is it relation object.
As we can see, RelatedObject(any relation) and ManyToManyRel(reverse side of ManyToMany) are handled. But, we also have reverse side of ForeignKey - ManyToOneRel. So yea, we have a problem here - appearance of bug #2818. So I decide to create this pull request. At least, it works perfectly for me.
FYI, I'm not checking for OneToOneRel, because there should be no duplications in this case.

Pull prequest - https://github.com/django/django/pull/1519

Should I write tests for it? I'm not very familiar with testwriting for django and contrib.admin has no tests(except really basic with Selenium), so I don't know when I'll finish it.

Change History (2)

comment:1 Changed 6 years ago by iorlas

Easy pickings: set

comment:2 Changed 6 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

Duplicate of #15819. Given that the patch on the ticket removes the block of code that your patch modifies, I think we should close this and try to write tests for the fix that's on that ticket.

Note: See TracTickets for help on using tickets.
Back to Top