﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28238	Changelist save method causing MemoryError	kainbozzetto	nobody	"We are encountering a MemoryError when in the Django admin and saving a changelist of a model that has a large amount of entries. This appears to be due to the size of the queryset returned by get_queryset().

We are currently circumventing this by modifying get_queryset() to check if the request method is a POST and then returning a queryset based on the ids of the form elements.

{{{#!python
def get_queryset(self, request):
    if request.method == 'POST':
        return ModelClass.objects.filter(
            id__in=self.get_changelist_ids(request))
    else:
        ...

def get_changelist_ids(self, request):
    ids = []
    n = 0
    while True:
        id = request.POST.get('form-{}-id'.format(n))
        if id:
            ids.append(id)
        else:
            break
        n += 1
    return ids
}}}

Our setup has 1GB RAM per process and a model with 100,000+ entries."	Cleanup/optimization	closed	contrib.admin	1.11	Normal	needsinfo	admin list_editable post get_queryset memoryerror		Unreviewed	0	0	0	0	0	0
