Code

Opened 3 years ago

Closed 3 years ago

#16326 closed Bug (fixed)

Un-pickled TemplateResponse objects can't be re-pickled

Reported by: natrius 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 natrius 3 years ago.
patch-16326-niran-2.diff (6.4 KB) - added by natrius 3 years ago.
ticket16326.diff (6.5 KB) - added by lrekucki 3 years ago.

Download all attachments as: .zip

Change History (8)

Changed 3 years ago by natrius

comment:1 Changed 3 years ago by natrius

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 3 years ago by aaugustin

  • Has patch set
  • Needs tests set
  • Triage Stage changed from Unreviewed to 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.

Changed 3 years ago by natrius

comment:3 Changed 3 years ago by natrius

  • Needs tests unset

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

comment:4 Changed 3 years ago by lrekucki

  • Triage Stage changed from Accepted to 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).

Last edited 3 years ago by lrekucki (previous) (diff)

Changed 3 years ago by lrekucki

comment:5 Changed 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [16568]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.