summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Clelland <ian@fullfactor.com>2012-09-28 12:57:38 -0700
committerLuke Plant <L.Plant.98@cantab.net>2012-10-26 01:40:33 +0100
commit3266c26eb22599a5577d41856baa04e99f87efe4 (patch)
tree8cbb3dd22014249b756636dac8bc305a602af8c9
parentbdcd2f6b105fffea0b8438625a29a1ccb2962680 (diff)
Properly support pickling of LazyObjects in Python 3.3
-rw-r--r--django/utils/functional.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py
index 085a8fce59..505931e158 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -293,6 +293,16 @@ class SimpleLazyObject(LazyObject):
self._setup()
return self._wrapped.__dict__
+ # Python 3.3 will call __reduce__ when pickling; these methods are needed
+ # to serialize and deserialize correctly. They are not called in earlier
+ # versions of Python.
+ @classmethod
+ def __newobj__(cls, *args):
+ return cls.__new__(cls, *args)
+
+ def __reduce__(self):
+ return (self.__newobj__, (self.__class__,), self.__getstate__())
+
# Need to pretend to be the wrapped class, for the sake of objects that care
# about this (especially in equality tests)
__class__ = property(new_method_proxy(operator.attrgetter("__class__")))