mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #20212 - __reduce__ should only be defined for Py3+.
This commit is contained in:
parent
4ba1c2e785
commit
e24d486fbc
2 changed files with 40 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue