diff -r b33d4705456a django/utils/functional.py
a
|
b
|
|
261 | 261 | else: |
262 | 262 | return copy.deepcopy(self._wrapped, memo) |
263 | 263 | |
| 264 | def __getstate__(self): |
| 265 | # We can't pickle the callable setupfunc, so avoid it. |
| 266 | if self._wrapped is empty: |
| 267 | self._setup() |
| 268 | return {'_wrapped': self._wrapped} |
| 269 | |
264 | 270 | # Need to pretend to be the wrapped class, for the sake of objects that care |
265 | 271 | # about this (especially in equality tests) |
266 | 272 | __class__ = property(new_method_proxy(operator.attrgetter("__class__"))) |
diff -r b33d4705456a tests/regressiontests/utils/simplelazyobject.py
a
|
b
|
|
1 | 1 | import copy |
| 2 | import pickle |
2 | 3 | |
3 | 4 | from django.utils.unittest import TestCase |
4 | 5 | from django.utils.functional import SimpleLazyObject, empty |
… |
… |
|
96 | 97 | self.assertTrue(x) |
97 | 98 | x = SimpleLazyObject(lambda: 0) |
98 | 99 | self.assertFalse(x) |
| 100 | |
| 101 | def test_pickle(self): |
| 102 | # See ticket #16563 |
| 103 | from django.contrib.auth.models import AnonymousUser |
| 104 | x = SimpleLazyObject(lambda: AnonymousUser()) |
| 105 | pickled = pickle.dumps(x) |
| 106 | unpickled = pickle.loads(pickled) |
| 107 | self.assertTrue(unpickled.is_anonymous()) |
| 108 | self.assertEqual(x, unpickled) |