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

Elasticsearch instrumentalization incorectly serializes object containing dots in field name #3034

Open
imamatory opened this issue Nov 21, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@imamatory
Copy link

imamatory commented Nov 21, 2024

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

@imamatory imamatory added the bug Something isn't working label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant