Skip to content

Commit

Permalink
Fix pickling docs with Nested fields
Browse files Browse the repository at this point in the history
Fixes #164, thanks arsham
  • Loading branch information
honzakral committed Jun 11, 2015
1 parent 2247816 commit 0f0bd3d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion elasticsearch_dsl/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, meta=None, **kwargs):
super(DocType, self).__init__(**kwargs)

def __getstate__(self):
return (self._d_, self.meta._d_)
return (self.to_dict(), self.meta._d_)

def __setstate__(self, state):
data, meta = state
Expand Down
3 changes: 2 additions & 1 deletion test_elasticsearch_dsl/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ def test_attribute_can_be_removed():
d.title

def test_doc_type_can_be_correctly_pickled():
d = MyDoc(title='Hello World!', meta={'id': 42})
d = DocWithNested(title='Hello World!', comments=[{'title': 'hellp'}], meta={'id': 42})
s = pickle.dumps(d)

d2 = pickle.loads(s)

assert d2 == d
assert 42 == d2.meta.id
assert 'Hello World!' == d2.title
assert [{'title': 'hellp'}] == d2.comments

def test_meta_is_accessible_even_on_empty_doc():
d = MyDoc()
Expand Down

0 comments on commit 0f0bd3d

Please sign in to comment.