#36751: Django Admin facets broken in 6.0
-------------------------------------+-------------------------------------
     Reporter:  Rafael Urben         |                    Owner:  Simon
                                     |  Charette
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  6.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * component:  contrib.admin => Database layer (models, ORM)
 * owner:  (none) => Simon Charette
 * status:  new => assigned

Comment:

 The ORM should likely cover this case but the fundamental problem here is
 that the admin creates empty `Q` objects and pass them to
 `Aggregate.filter` when there are no `param_dict`.

 Notice how the following patch addresses the problem

 {{{#!diff
 diff --git a/django/contrib/admin/filters.py
 b/django/contrib/admin/filters.py
 index 10a039af2a..d1967e0b88 100644
 --- a/django/contrib/admin/filters.py
 +++ b/django/contrib/admin/filters.py
 @@ -534,7 +534,9 @@ class DateFieldListFilter(FieldListFilter):

      def get_facet_counts(self, pk_attname, filtered_qs):
          return {
 -            f"{i}__c": models.Count(pk_attname,
 filter=models.Q(**param_dict))
 +            f"{i}__c": models.Count(
 +                pk_attname, filter=(models.Q(**param_dict) if param_dict
 else None)
 +            )
              for i, (_, param_dict) in enumerate(self.links)
          }
 }}}

 Before b8e5a8a9a2a767f584cbe89a878a42363706f939, which is effectively the
 origin of the regression, we we're turning `Q()` to `None` before
 assigning to `AggregateFilter` which elided such bogus filters.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36751#comment:4>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019ab161c848-eafb767b-d46d-4318-94a3-e15e27820903-000000%40eu-central-1.amazonses.com.

Reply via email to