#3012: Traceback when using locmem cache backend
--------------------------+-------------------------------------------------
Reporter: Alex Dedul | Owner: jacob
Status: closed | Component: Cache system
Version: | Resolution: fixed
Keywords: | Stage: Ready for checkin
Has_patch: 1 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
--------------------------+-------------------------------------------------
Comment (by gwilson):
So after a little bit of playing it seems that the tracebacks above are
possibly caused by `deepcopy()` getting called on an `HttpResponse` object
after `iter()` had been called on the `HttpResponse` object.
`HttpResponse.__iter__` sets `self._iterator`, and after that a `copy()`
or `deepcopy()` will fail since `self._iterator` tries to get copied.
{{{
>>> from django.http import HttpResponse
>>> import copy
>>> import pickle
>>> r=HttpResponse()
>>> copy.deepcopy(r)
<django.http.HttpResponse object at 0x83f360c>
>>> pickle.dumps(r)
"ccopy_reg\n_reconstructor\np0\n(cdjango.http\nHttpResponse\np1\nc__builtin__\nobject\np2\nNtp3\nRp4\n(dp5\nS'headers'\np6\n(dp7\nS'
Content-Type'\np8\nS'text/html;
charset=utf-8'\np9\nssS'_charset'\np10\nS'utf-8'\np11\nsS'_container'\np12\n(lp13\nS''\np14\nasS'cookies'\np15\ng0\n(cCookie\nSimpleCookie\np16\nc__builtin__\ndict\np17\n(dp18\ntp19\nRp20\nsS'_is_string'\np21\nI01\nsb."
>>> iter(r)
<django.http.HttpResponse object at 0x83f344c>
>>> copy.deepcopy(r)
Traceback (most recent call last):
File "<console>", line 1, in ?
File "/usr/lib/python2.4/copy.py", line 204, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.4/copy.py", line 351, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python2.4/copy.py", line 174, in deepcopy
y = copier(x, memo)
File "/usr/lib/python2.4/copy.py", line 268, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.4/copy.py", line 204, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.4/copy.py", line 336, in _reconstruct
y = callable(*args)
File "/usr/lib/python2.4/copy_reg.py", line 92, in __newobj__
return cls.__new__(cls, *args)
TypeError: object.__new__(listiterator) is not safe, use
listiterator.__new__()
>>> pickle.dumps(r)
Traceback (most recent call last):
File "<console>", line 1, in ?
File "/usr/lib/python2.4/pickle.py", line 1386, in dumps
Pickler(file, protocol, bin).dump(obj)
File "/usr/lib/python2.4/pickle.py", line 231, in dump
self.save(obj)
File "/usr/lib/python2.4/pickle.py", line 338, in save
self.save_reduce(obj=obj, *rv)
File "/usr/lib/python2.4/pickle.py", line 433, in save_reduce
save(state)
File "/usr/lib/python2.4/pickle.py", line 293, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.4/pickle.py", line 663, in save_dict
self._batch_setitems(obj.iteritems())
File "/usr/lib/python2.4/pickle.py", line 677, in _batch_setitems
save(v)
File "/usr/lib/python2.4/pickle.py", line 313, in save
rv = reduce(self.proto)
File "/usr/lib/python2.4/copy_reg.py", line 69, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle listiterator objects
}}}
The strange thing is that when testing out the `cache_page` decorator when
using `deepcopy()` in locmem cache, the exception surfaces, but when using
pickle I get no errors.
--
Ticket URL: <http://code.djangoproject.com/ticket/3012#comment:28>
Django Code <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---