Opened 13 years ago
Closed 13 years ago
#16326 closed Bug (fixed)
Un-pickled TemplateResponse objects can't be re-pickled
Reported by: | Niran Babalola | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Pickling a TemplateResponse
removes attributes that deal with rendering, presumably to make it clear that un-pickled TemplateResponses
are completely baked and you can't do the typical things you'd do with a normal TemplateResponse
. However, there's no check that ensures that the attributes exist before removing them, so if you try to re-pickle a TemplateResponse
, you get a KeyError
.
Attachments (3)
Change History (8)
by , 13 years ago
Attachment: | patch-16326-niran.diff added |
---|
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Has patch: | set |
---|---|
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
Since TemplateResponse
contains code to deal with pickling, it's reasonable to expect pickling - unpickling - pickling to work.
I think the rationale for stripping these attributes is to avoid storing a large amount of computed data. I'd expect them to be regenerated during unpickling, or on demand when the response is rendered; I haven't checked the details.
by , 13 years ago
Attachment: | patch-16326-niran-2.diff added |
---|
comment:3 by , 13 years ago
Needs tests: | unset |
---|
Added a new patch that raises the exception I described earlier and tests everything.
comment:4 by , 13 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
The patch and tests look good. Only missing thing is from __future__ import with_statement
for Python 2.5 (attaching fixed patch).
by , 13 years ago
Attachment: | ticket16326.diff added |
---|
I've attached a patch that fixes the problem. A further improvement would be for an un-pickled
TemplateResponse
to raise a more explicit exception when the removed attributes are accessed so it's clear what is going on.