From e24d486fbc0b1c42abe8b54217ff428e449c48cc Mon Sep 17 00:00:00 2001 From: Daniel Lindsley Date: Mon, 20 May 2013 22:17:56 -0700 Subject: Fixed #20212 - __reduce__ should only be defined for Py3+. --- tests/utils_tests/test_simplelazyobject.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/utils_tests/test_simplelazyobject.py') diff --git a/tests/utils_tests/test_simplelazyobject.py b/tests/utils_tests/test_simplelazyobject.py index f925e01eb6..ca7c2672eb 100644 --- a/tests/utils_tests/test_simplelazyobject.py +++ b/tests/utils_tests/test_simplelazyobject.py @@ -161,3 +161,25 @@ class TestUtilsSimpleLazyObject(TestCase): self.assertNotEqual(lazy1, lazy3) self.assertTrue(lazy1 != lazy3) self.assertFalse(lazy1 != lazy2) + + 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) -- cgit v1.3