#32682: Deleting objects after searching related many to many field crashes the
admin page
-------------------------------------+-------------------------------------
Reporter: Zain Patel | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.2
Severity: Release blocker | Resolution:
Keywords: regression, admin, | Triage Stage: Accepted
delete |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* owner: nobody => Mariusz Felisiak
* status: new => assigned
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
This exception was introduce in 6307c3f1a123f5975c73b231e8ac4f115fd72c0d
and revealed a possible data loss issue in the admin. IMO we should use
`Exists()` instead of `distinct()`, e.g.
{{{
diff --git a/django/contrib/admin/views/main.py
b/django/contrib/admin/views/main.py
index fefed29933..e9816ddd15 100644
--- a/django/contrib/admin/views/main.py
+++ b/django/contrib/admin/views/main.py
@@ -475,9 +475,8 @@ class ChangeList:
if not qs.query.select_related:
qs = self.apply_select_related(qs)
- # Set ordering.
+ # Get ordering.
ordering = self.get_ordering(request, qs)
- qs = qs.order_by(*ordering)
# Apply search results
qs, search_use_distinct =
self.model_admin.get_search_results(request, qs, self.query)
@@ -487,11 +486,14 @@ class ChangeList:
new_params=remaining_lookup_params,
remove=self.get_filters_params(),
)
+
# Remove duplicates from results, if necessary
if filters_use_distinct | search_use_distinct:
- return qs.distinct()
+ from django.db.models import Exists, OuterRef
+ qs = qs.filter(pk=OuterRef('pk'))
+ return
self.root_queryset.filter(Exists(qs)).order_by(*ordering)
else:
- return qs
+ return qs.order_by(*ordering)
def apply_select_related(self, qs):
if self.list_select_related is True:
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32682#comment:1>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/063.d6bad0a3f7eb0b161f196e3c762cb731%40djangoproject.com.