diff options
| author | Daniel Lindsley <daniel@toastdriven.com> | 2013-05-20 22:17:56 -0700 |
|---|---|---|
| committer | Daniel Lindsley <daniel@toastdriven.com> | 2013-05-21 10:17:27 -0700 |
| commit | cb9aaac91fb41b29b3d0d94f3cd208123c02a2ca (patch) | |
| tree | c757677c93a6d3d6bb2bb32f2bcf28cced6799cf /tests | |
| parent | bac187c0d8e829fb3ca2ca82965eabbcbcb6ddd5 (diff) | |
[1.5.x] Fixed #20212 - __reduce__ should only be defined for Py3+.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/utils/simplelazyobject.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/regressiontests/utils/simplelazyobject.py b/tests/regressiontests/utils/simplelazyobject.py index 3f81e8f608..2dd382cf04 100644 --- a/tests/regressiontests/utils/simplelazyobject.py +++ b/tests/regressiontests/utils/simplelazyobject.py @@ -121,3 +121,25 @@ class TestUtilsSimpleLazyObject(TestCase): self.assertEqual(unpickled, x) self.assertEqual(six.text_type(unpickled), six.text_type(x)) self.assertEqual(unpickled.name, x.name) + + def test_pickle_py2_regression(self): + from django.contrib.auth.models import User + + # See ticket #20212 + user = User.objects.create_user('johndoe', 'john@example.com', 'pass') + x = SimpleLazyObject(lambda: user) + + # This would fail with "TypeError: can't pickle instancemethod objects", + # only on Python 2.X. + pickled = pickle.dumps(x) + + # Try the variant protocol levels. + pickled = pickle.dumps(x, 0) + pickled = pickle.dumps(x, 1) + pickled = pickle.dumps(x, 2) + + if not six.PY3: + import cPickle + + # This would fail with "TypeError: expected string or Unicode object, NoneType found". + pickled = cPickle.dumps(x) |
