Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import pickle
from django.utils.functional import SimpleLazyObject
class FooBase(object):
def __reduce__(self):
self.__dict__['_version'] = 1
return super(FooBase, self).__reduce__()
class Foo(FooBase):
def __init__(self, foobase):
self.__dict__ = foobase.__dict__
self._foo = foobase
lazy_foo = SimpleLazyObject(lambda: Foo(FooBase()))
print pickle.dumps(lazy_foo) # raises an error
# run in a ./manage.py shell
import pickle
from django.contrib.auth.models import User #any model will do
from django.utils.functional import SimpleLazyObject
user = User.objects.get(username='benkraft')
lazy_user = SimpleLazyObject(lambda: user)
pickle.loads(pickle.dumps(lazy_user)) # warns
import pickle
from django.utils.functional import SimpleLazyObject
class Foo(object):
def __reduce__(self):
self.__dict__['_version'] = 1
return super(Foo, self).__reduce__()
def __init__(self):
self._foo = self
lazy_foo = SimpleLazyObject(lambda: Foo())
print pickle.dumps(lazy_foo) # raises an error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.