Ticket #16563: ticket_16563.2.diff

File ticket_16563.2.diff, 1.5 KB (added by lukeplant, 4 years ago)

Small fix to patch (unneeded import)

  • django/utils/functional.py

    diff -r b33d4705456a django/utils/functional.py
    a b  
    261261        else:
    262262            return copy.deepcopy(self._wrapped, memo)
    263263
     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
    264270    # Need to pretend to be the wrapped class, for the sake of objects that care
    265271    # about this (especially in equality tests)
    266272    __class__ = property(new_method_proxy(operator.attrgetter("__class__")))
  • tests/regressiontests/utils/simplelazyobject.py

    diff -r b33d4705456a tests/regressiontests/utils/simplelazyobject.py
    a b  
    11import copy
     2import pickle
    23
    34from django.utils.unittest import TestCase
    45from django.utils.functional import SimpleLazyObject, empty
     
    9697        self.assertTrue(x)
    9798        x = SimpleLazyObject(lambda: 0)
    9899        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)
Back to Top