#34605 closed Cleanup/optimization (needsinfo)

Add distinct support for ListFilters

Reported by: Karolis Ryselis Owned by: nobody
Component: contrib.admin Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Current implementation of ChangeList.get_filters() returns may_have_duplicates, which only accounts for field list filters, but not custom list filters where no field is used. One possibility is to add .distinct() in the queryset() method of the filter, but it prevents the objects to be deleted using changelist because .delete() cannot be called after .distinct(). Another approach is to use the approach from ChangeList.get_queryset() - subquery + Exists() in filter's queryset, however, this adds unnecessary complexity on the query if multiple such filters are applied or other filters/search may have duplicates - it would then nest the subqueries, which is suboptimal.

I am not sure about the best solution for this - maybe add method may_have_duplicates on filter spec classes, which defaults to current lookup_needs_distinct call for field filters and raises NotImplementedError for the others?

Change History (3)

comment:1 by Karolis Ryselis, 18 months ago

Type: UncategorizedCleanup/optimization

comment:2 by Natalia Bidart, 18 months ago

Component: Uncategorizedcontrib.admin

Hello, thank you for your report.

Could you please provide a minimal django app showcasing the issue? That will help us further triage this report.Thank you!

comment:3 by Natalia Bidart, 18 months ago

Resolution: needsinfo
Status: newclosed

Forgot to close as needsinfo, but I'm happy to reopen when more information is provided. Thanks!

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