mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
[1.5.x] Fixed #20212 - __reduce__ should only be defined for Py3+.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user