Opened 11 years ago

Closed 11 years ago

#5808 closed (duplicate)

Cannot pickle the default filters

Reported by: simon@… Owned by: nobody
Component: Core (Other) Version: master
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: UI/UX:


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:


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@… 11 years ago.

Download all attachments as: .zip

Change History (5)

Changed 11 years ago by simon@…

Attachment: django-pickle-filters.patch added


comment:1 Changed 11 years ago by Malcolm Tredinnick

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 Changed 11 years ago by Malcolm Tredinnick

Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 11 years ago by Simon Law <simon@…>

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.

    _dec.__name__ = func.__name__ 
except TypeError:

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 Changed 11 years ago by Jacob

Resolution: duplicate
Status: newclosed

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

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