Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Object/Nested from mutating the inner doc_class' mapping #1255

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"},
}