Opened 6 years ago

Closed 5 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


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 6 years ago.
patch-16326-niran-2.diff (6.4 KB) - added by Niran Babalola 6 years ago.
ticket16326.diff (6.5 KB) - added by Łukasz Rekucki 6 years ago.

Download all attachments as: .zip

Change History (8)

Changed 6 years ago by Niran Babalola

Attachment: patch-16326-niran.diff added

comment:1 Changed 6 years ago by Niran Babalola

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 Changed 6 years ago by Aymeric Augustin

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.

Changed 6 years ago by Niran Babalola

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

comment:3 Changed 6 years ago by Niran Babalola

Needs tests: unset

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

comment:4 Changed 6 years ago by Łukasz Rekucki

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).

Last edited 6 years ago by Łukasz Rekucki (previous) (diff)

Changed 6 years ago by Łukasz Rekucki

Attachment: ticket16326.diff added

comment:5 Changed 5 years ago by Jannis Leidel

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