Describe your environment
OS: OS X Sequoia 15.01
Python version: Python 3.11.7
Package version: 0.47b.0
Elasticsearch: 6
What happened?
For specific queries with both field names 'name' and 'name.morph' ElasticsearchInstrumentor creates the wrong db statement and breaks the original query object.
Steps to Reproduce
Form a request like this:
body = {
'from': 0,
'highlight': {'fields': {'name': {},
'name.morph': {}}},
'query': {'bool': {'filter': [{'terms': {'status': ['ACTIVE']}}]}},
'size': 3}
Expected Result
Db statement (note fields key)
("{'from': 0, 'highlight': {'fields': {'name': {}, 'name.morph': {}}}, 'query': "
"{'bool': {'filter': '?'}}, 'size': 3}")
Original body object:
{'from': 0,
'highlight': {'fields': {'name': {'morph': {}},
'name.morph': {'morph': {}}}},
'query': {'bool': {'filter': [{'terms': {'status': ['ACTIVE']}}]}},
'size': 3}
Actual Result
Db statement (note fields key)
("{'from': 0, 'highlight': {'fields': {'name': {'morph': {...}}}}, 'query': "
"{'bool': {'filter': '?'}}, 'size': 3}")
The original body object becomes:
{'from': 0,
'highlight': {'fields': {'name': {'morph': <Recursion on dict with id=4366695936>},
'name.morph': {'morph': <Recursion on dict with id=4366695936>}}},
'query': {'bool': {'filter': [{'terms': {'status': ['ACTIVE']}}]}},
'size': 3}
This body object is impossible to serialize so it breaks further on query serialization stage
Additional context
sanitize_body function mutates the original body and this is not good by itself.
Would you like to implement a fix?
Yes
Describe your environment
OS: OS X Sequoia 15.01
Python version: Python 3.11.7
Package version: 0.47b.0
Elasticsearch: 6
What happened?
For specific queries with both field names 'name' and 'name.morph'
ElasticsearchInstrumentorcreates the wrong db statement and breaks the original query object.Steps to Reproduce
Form a request like this:
Expected Result
Db statement (note
fieldskey)Original body object:
{'from': 0, 'highlight': {'fields': {'name': {'morph': {}}, 'name.morph': {'morph': {}}}}, 'query': {'bool': {'filter': [{'terms': {'status': ['ACTIVE']}}]}}, 'size': 3}Actual Result
Db statement (note
fieldskey)The original body object becomes:
{'from': 0, 'highlight': {'fields': {'name': {'morph': <Recursion on dict with id=4366695936>}, 'name.morph': {'morph': <Recursion on dict with id=4366695936>}}}, 'query': {'bool': {'filter': [{'terms': {'status': ['ACTIVE']}}]}}, 'size': 3}This body object is impossible to serialize so it breaks further on query serialization stage
Additional context
sanitize_bodyfunction mutates the original body and this is not good by itself.Would you like to implement a fix?
Yes