Re: [Django] #10919: Add an option to disable display of related items on admin's delete confirmation page (to prevent large memory usage on complex objects)

31 views
Skip to first unread message

Django

unread,
Nov 29, 2015, 11:30:55 PM11/29/15
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
------------------------------------+------------------------------------
Reporter: tobias | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Changes (by darkpixel):

* cc: aaron@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 31, 2016, 5:18:27 AM1/31/16
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
------------------------------------+------------------------------------
Reporter: tobias | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Changes (by sasha0):

* cc: sasha@… (added)


Comment:

A property for `ModelAdmin` ?

--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:6>

Django

unread,
May 20, 2016, 10:48:13 AM5/20/16
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
------------------------------------+------------------------------------
Reporter: tobias | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

Comment (by nijel):

Adding such property to ModelAdmin sounds like a good idea.

I've workarounded it myself by removing deleted_objects before rendering
the template:

{{{
def render_delete_form(self, request, context):
context['deleted_objects'] = [_('Object listing disabled')]
return super(ProjectAdmin, self).render_delete_form(request,
context)
}}}

This way I will get the summary (so that user has idea what he is
deleting), but not object list as it is too long to get displayed.

--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:7>

Django

unread,
May 20, 2016, 10:48:27 AM5/20/16
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
------------------------------------+------------------------------------
Reporter: tobias | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Changes (by nijel):

* cc: michal@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:8>

Django

unread,
Oct 4, 2018, 4:08:39 PM10/4/18
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
------------------------------------+------------------------------------
Reporter: Tobias McNulty | Owner: nobody

Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

Comment (by Sergii Lapin):

Actually, removing **deleted_objects** from **context** doesn't prevent
from collecting related items by
**django.contrib.admin.utils.NestedObjects** in
**django.contrib.admin.utils.get_deleted_objects**
Maybe it better off to override **get_deleted_objects** function (Django
2+ has this method inside AdminModel class). But there appears new issue:
How to check permissions and protected foreign keys for related items?..

--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:9>

Django

unread,
Oct 4, 2018, 4:10:37 PM10/4/18
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
------------------------------------+------------------------------------
Reporter: Tobias McNulty | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Changes (by Sergii Lapin):

* cc: Sergii Lapin (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:10>

Django

unread,
Jan 7, 2020, 8:12:52 AM1/7/20
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
------------------------------------+------------------------------------
Reporter: Tobias McNulty | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

Comment (by Sivakumar R):

Replying to [ticket:10919 Tobias McNulty]:
> I recently tried to delete an object in the admin that had several
million related objects.
>
> The server quickly ran out of memory as the apache process's memory
usage ballooned upwards to near a gigabyte.
>
> I assume this is because it was trying to create an HTML page listing
out all the related objects.
>
> Can the admin page do a count and/or limit to avoid this?
>
> I'm using Django 1.1 trunk (r10628), mod_wsgi 2.0, and apache 2.2.8.
I tried one method. I don't want related objects. So i overrided the
get_deleted_object() method. But i removed "to_delete =
collector.nested(format_callback)" line and return just the
queryset(objs). So it will show only the objects to delete. Is there any
issue with this method? If there any, please tell me.

--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:11>

Django

unread,
Jan 7, 2020, 8:15:11 AM1/7/20
to django-...@googlegroups.com

Comment (by Sivakumar R):

--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:12>

Django

unread,
Mar 17, 2020, 11:44:48 AM3/17/20
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
------------------------------------+------------------------------------
Reporter: Tobias McNulty | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

Comment (by terminator14):

I am using Django 2.2.10, and this is still an issue.
If I am using Django Admin to delete an object with millions of related
records, it tries to generate the list, takes too long, and my browser
gives up waiting, showing an error loading the page.

I'm not sure how difficult this is to do, but I have some thoughts:

When deleting an object from Django Admin, the summary section is great,
but I really like the fact that Django Admin lists all effected related
objects. If the summary section was the only thing on the page, someone
deleting an object may think "pfft - I know exactly what happens if I
delete this", and delete it without a second thought, without even
bothering to glance at the summary of the number of related objects that
will be effected. I know this sounds like a "that's their problem" type of
deal, but if we can prevent this, why wouldn't we?

The list of effected objects that Django Admin currently provides is very
clear. As soon as the page loads, if you think you are about to delete one
object, but you see a massive list of effected stuff, you immediately
start looking into what you are deleting, and why it effects more than
what you expected.

I think a good solution would be a middle-ground, rather than disabling
the list of related objects.

If you are about to delete an object with a million related objects, have
django do a DB query with something like "limit 100". It will pull 100
related objects, quickly generate the HTML page without trying to list a
million objects on the page, and the user will still have the advantage of
quickly seeing that his delete operation will effect a ton of objects,
since he'll have a hundred objects listed on the page.

To make things clear, add a message at the bottom that says something like
"and 999,900 others" or something. This will tell them that the 100
objects listed aren't the only ones to be deleted.

Any thoughts?

--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:13>

Django

unread,
Apr 18, 2023, 4:41:40 PM4/18/23
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
-------------------------------------+-------------------------------------
Reporter: Tobias McNulty | Owner: Ramez
| Issac
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev

Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ramez Issac):

* owner: nobody => Ramez Issac
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:14>

Django

unread,
Mar 8, 2026, 5:52:07 PM (6 days ago) Mar 8
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
------------------------------------+------------------------------------
Reporter: Tobias McNulty | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------
Comment (by Rodrigo Vieira):

That's a pretty old ticket, but I'd love to give this a go, I think it
could be a nice QoL improvement.

For example if we try to delete a model with thousands of children (which
in turn may be their own children), not only the page may take minutes to
load and overload the browser, but the delete button is pushed **all the
way to the bottom**, so the user will have to wait for the page to load
and the browser to render everything to access the button (maybe even
moving the delete button UP, after the summary, could be an improvement?)

I like @terminator14's idea above of having a limit of, say, 100, and then
we render something like `...and N more` and the end. Probably the
cleanest solution is to tweak
[https://github.com/django/django/blob/main/django/contrib/admin/utils.py#L127
get_deleted_objects] to truncate the list and do some math to know which
number to put on the "..and N more" text.

One thing I'm not sure is where such config value for the limit of nodes
to list should reside. Would we expect for it to be overridable via
settings.py?

Django

unread,
9:27 AM (1 hour ago) 9:27 AM
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
-------------------------------------+-------------------------------------
Reporter: Tobias McNulty | Owner: Rodrigo
| Vieira
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Rodrigo Vieira):

* owner: nobody => Rodrigo Vieira
* status: new => assigned

Comment:

I am starting to prepare a PR for it:
https://github.com/django/django/pull/20903
--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:15>

Django

unread,
9:56 AM (17 minutes ago) 9:56 AM
to django-...@googlegroups.com
#10919: Add an option to disable display of related items on admin's delete
confirmation page (to prevent large memory usage on complex objects)
-------------------------------------+-------------------------------------
Reporter: Tobias McNulty | Owner: Rodrigo
| Vieira
Type: New feature | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: admin memory limit | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Rodrigo Vieira):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/10919#comment:16>
Reply all
Reply to author
Forward
0 new messages