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)

patch-16326-niran.diff (2.4 KB ) - added by Niran Babalola 13 years ago.
patch-16326-niran-2.diff (6.4 KB ) - added by Niran Babalola 13 years ago.
ticket16326.diff (6.5 KB ) - added by Łukasz Rekucki 13 years ago.

Download all attachments as: .zip

Change History (8)

by Niran Babalola, 13 years ago

Attachment: patch-16326-niran.diff added

comment:1 by Niran Babalola, 13 years ago

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.

comment:2 by Aymeric Augustin, 13 years ago

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted

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 Niran Babalola, 13 years ago

Attachment: patch-16326-niran-2.diff added

comment:3 by Niran Babalola, 13 years ago

Needs tests: unset

Added a new patch that raises the exception I described earlier and tests everything.

comment:4 by Łukasz Rekucki, 13 years ago

Triage Stage: AcceptedReady for checkin

The patch and tests look good. Only missing thing is {{{from future import with_statement}} for Python 2.5 (attaching fixed patch).

Version 0, edited 13 years ago by Łukasz Rekucki (next)

by Łukasz Rekucki, 13 years ago

Attachment: ticket16326.diff added

comment:5 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [16568]:

Fixed #16326 -- Fixed re-pickling of unpickled TemplateResponse instances. Thanks, natrius and lrekucki.

Note: See TracTickets for help on using tickets.
Back to Top