Created
March 23, 2011 17:29
-
-
Save tfausak/883542 to your computer and use it in GitHub Desktop.
Minimal example that causes an error when deep copying a mongoengine Document.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from copy import deepcopy | |
from mongoengine import Document, ReferenceField, connect | |
class Foo(Document): | |
pass | |
class Bar(Document): | |
foo = ReferenceField(Foo) | |
connect('tmp-deepcopy') | |
Foo.drop_collection() | |
foo = Foo() | |
foo.save() | |
Bar.drop_collection() | |
bar = Bar(foo=foo) | |
bar.save() | |
deepcopy(bar) # succeeds | |
bar = Bar.objects.get(id=bar.id) | |
deepcopy(bar) # fails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Traceback (most recent call last): | |
File "deepcopy.py", line 22, in <module> | |
deepcopy(Bar.objects.get(id=bar.id)) | |
File "/usr/lib/python2.6/copy.py", line 189, in deepcopy | |
y = _reconstruct(x, rv, 1, memo) | |
File "/usr/lib/python2.6/copy.py", line 338, in _reconstruct | |
state = deepcopy(state, memo) | |
File "/usr/lib/python2.6/copy.py", line 162, in deepcopy | |
y = copier(x, memo) | |
File "/usr/lib/python2.6/copy.py", line 255, in _deepcopy_dict | |
y[deepcopy(key, memo)] = deepcopy(value, memo) | |
File "/usr/lib/python2.6/copy.py", line 162, in deepcopy | |
y = copier(x, memo) | |
File "/usr/lib/python2.6/copy.py", line 255, in _deepcopy_dict | |
y[deepcopy(key, memo)] = deepcopy(value, memo) | |
File "/usr/lib/python2.6/copy.py", line 171, in deepcopy | |
copier = getattr(x, "__deepcopy__", None) | |
File "build/bdist.linux-i686/egg/bson/dbref.py", line 81, in __getattr__ | |
KeyError: '__deepcopy__' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment