From 9822d88ca0dd855a668f9c33447aeac45a9768ac Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 23 Feb 2018 12:47:36 -0500 Subject: [PATCH] Removed using argument from admin's get_deleted_objects(). --- django/contrib/admin/actions.py | 5 +---- django/contrib/admin/options.py | 4 +--- django/contrib/admin/utils.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py index 319cb14307..d4bc3daf85 100644 --- a/django/contrib/admin/actions.py +++ b/django/contrib/admin/actions.py @@ -6,7 +6,6 @@ from django.contrib import messages from django.contrib.admin import helpers from django.contrib.admin.utils import get_deleted_objects, model_ngettext from django.core.exceptions import PermissionDenied -from django.db import router from django.template.response import TemplateResponse from django.utils.translation import gettext as _, gettext_lazy @@ -28,12 +27,10 @@ def delete_selected(modeladmin, request, queryset): if not modeladmin.has_delete_permission(request): raise PermissionDenied - using = router.db_for_write(modeladmin.model) - # Populate deletable_objects, a data structure of all related objects that # will also be deleted. deletable_objects, model_count, perms_needed, protected = get_deleted_objects( - queryset, request.user, modeladmin.admin_site, using, + queryset, request.user, modeladmin.admin_site, ) # The user has already confirmed the deletion. diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 369fba18e1..f9f5f85ef3 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1750,12 +1750,10 @@ class ModelAdmin(BaseModelAdmin): if obj is None: return self._get_obj_does_not_exist_redirect(request, opts, object_id) - using = router.db_for_write(self.model) - # Populate deleted_objects, a data structure of all related objects that # will also be deleted. deleted_objects, model_count, perms_needed, protected = get_deleted_objects( - [obj], request.user, self.admin_site, using, + [obj], request.user, self.admin_site, ) if request.POST and not protected: # The user has confirmed the deletion. diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py index 633d4d69df..b8df69c1d8 100644 --- a/django/contrib/admin/utils.py +++ b/django/contrib/admin/utils.py @@ -4,7 +4,7 @@ from collections import defaultdict from django.contrib.auth import get_permission_codename from django.core.exceptions import FieldDoesNotExist -from django.db import models +from django.db import models, router from django.db.models.constants import LOOKUP_SEP from django.db.models.deletion import Collector from django.forms.utils import pretty_name @@ -117,7 +117,7 @@ def flatten_fieldsets(fieldsets): return field_names -def get_deleted_objects(objs, user, admin_site, using): +def get_deleted_objects(objs, user, admin_site): """ Find all objects related to ``objs`` that should also be deleted. ``objs`` must be a homogeneous iterable of objects (e.g. a QuerySet). @@ -125,6 +125,12 @@ def get_deleted_objects(objs, user, admin_site, using): Return a nested list of strings suitable for display in the template with the ``unordered_list`` filter. """ + try: + obj = objs[0] + except IndexError: + return [], {}, set(), [] + else: + using = router.db_for_write(obj._meta.model) collector = NestedObjects(using=using) collector.collect(objs) perms_needed = set()