Skip to content

Commit

Permalink
Prevent Object and Nested mutating inner doc_class mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
l1nd3r0th committed Jul 16, 2020
1 parent 46e8002 commit 744211b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion elasticsearch_dsl/field.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import copy
import ipaddress

try:
Expand Down Expand Up @@ -151,7 +152,7 @@ def __init__(self, doc_class=None, dynamic=None, properties=None, **kwargs):
if dynamic is not None:
self._doc_class._doc_type.mapping.meta('dynamic', dynamic)

self._mapping = self._doc_class._doc_type.mapping
self._mapping = copy.deepcopy(self._doc_class._doc_type.mapping)
super(Object, self).__init__(**kwargs)

def __getitem__(self, name):
Expand Down
17 changes: 17 additions & 0 deletions test_elasticsearch_dsl/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,20 @@ class Index:
assert c.meta.fields._tags == ['search']
assert c.meta.fields._routing == 'es'
assert c._tagline == 'You know, for search'

def test_nested_and_object_inner_doc():
class MySubDocWithNested(MyDoc):
nested_inner = field.Nested(MyInner)

props = MySubDocWithNested._doc_type.mapping.to_dict()['properties']
assert props == {
"created_at": {"type": "date"},
"inner": {"properties": {"old_field": {"type": "text"}}, "type": "object"},
"name": {"type": "text"},
"nested_inner": {
"properties": {"old_field": {"type": "text"}},
"type": "nested",
},
"title": {"type": "keyword"},
}

0 comments on commit 744211b

Please sign in to comment.