Opened 17 years ago

Closed 17 years ago

#5808 closed (duplicate)

Cannot pickle the default filters

Reported by: simon@… Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: template pickle filter
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Reproduction code:

from django import template
t = template.Template("{{ firstname|capfirst }}")
c = template.Context("firstname": "simon")
p = pickle.dumps(t)
print pickle.loads(p).render(c)

Expected result:

Simon

Actual result:

<class 'pickle.PicklingError'>: Can't pickle <function _dec at 0x83c010c>: it's not found as django.template.defaultfilters._dec

Attachments (1)

django-pickle-filters.patch (469 bytes ) - added by simon@… 17 years ago.
Patch

Download all attachments as: .zip

Change History (5)

by simon@…, 17 years ago

Attachment: django-pickle-filters.patch added

Patch

comment:1 by Malcolm Tredinnick, 17 years ago

The __name__ attribute is write-only in Python 2.3.

This might be fixed by Jeremy Dunck's recent decorator work (which isn't going in just yet because we need to get some license clearance).

We're probably unlikely to jump through a lot of hoops to make pickling work, though, if more than this is required.

comment:2 by Malcolm Tredinnick, 17 years ago

Triage Stage: UnreviewedDesign decision needed

comment:3 by Simon Law <simon@…>, 17 years ago

I see. This is related to #3558.

Since name is read-only in Python 2.3, it still possible for this to work by wrapping the patch in a try statement.

try:
    _dec.__name__ = func.__name__ 
except TypeError:
    pass

This breaks pickling in Python 2.3, but permits it elsewhere.

Pickling is useful so that we can cache templates in memcached. If template parsing is non-trivial, you really want to cache these objects.

comment:4 by Jacob, 17 years ago

Resolution: duplicate
Status: newclosed

As Malcolm said, this is a duplicate of #5701.

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