﻿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
6308	QueryDict won't release objects between requests when request.POST is copy() ed	Yasushi Masuda <whosaysni@…>	Yasushi Masuda	"Hi,
There seems to be the population of container argument in QueryDict.__deepcopy__(), which should cause incremental
(and unreleased) population of POST data between requests. Here is the relevant code in django.http.__init__.py:
{{{
174    def __deepcopy__(self, memo={}):
175	        import copy
176	        result = self.__class__('', mutable=True)
177	        memo[id(self)] = result
178	        for key, value in dict.items(self):
179	            dict.__setitem__(result, copy.deepcopy(key, memo), copy.deepcopy(value, memo))
}}}

The behaviour can be easily demonstrated as follows: 
{{{
from django.conf.urls.defaults import *
from django.http import HttpResponse, QueryDict
from django.template import Template, Context

def demo(request):
  request.POST.copy()
  t = Template(
    '<html><body>'
    '<form method=""POST"" action=""/""><input name=""llama"" type=""submit""></form>'
    '{% for item in memo %}llama at {{ item.0 }}, {% endfor %}'
    '</body></html>')
  memo = QueryDict.__deepcopy__.im_func.func_defaults[0].items()
  c = Context({'memo': memo})
  return HttpResponse(t.render(c))

urlpatterns = patterns('', url(r'^$', demo))
}}}

You should see llamas are populating between requests, and after enormous POST requests,
You can see the process size is significantly increased.

I think (I'm not sure the reason why memo is directly populated) it can be fixed rewriting __deepcopy__ as follows:
{{{
    def __deepcopy__(self, memo={}):
        import copy
        result = self.__class__('', mutable=True)
        m = dict(memo.items())
        m[id(self)] = result
        for key, value in dict.items(self):
            dict.__setitem__(result, copy.deepcopy(key, m), copy.deepcopy(value, m))
        return result
}}}

Thanks."		closed	Core (Other)	dev		fixed	request.POST.copy, memory issue		Unreviewed	0	0	0	0	0	0
