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

[BUG] Collapse not preserved when chaining a Search instance #769

Closed
Mdelaf opened this issue Jun 27, 2024 · 7 comments
Closed

[BUG] Collapse not preserved when chaining a Search instance #769

Mdelaf opened this issue Jun 27, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@Mdelaf
Copy link

Mdelaf commented Jun 27, 2024

What is the bug?

Chain operations over a Search object do not preserve the _collapse attribute.

How can one reproduce the bug?

>>> from pprint import pp
>>> from opensearchpy import Search
>>> 
>>> s = Search(index="index_name")
>>> s = s.filter("term", color="red")
>>> pp(s.to_dict())
{'query': {'bool': {'filter': [{'term': {'color': 'red'}}]}}}
>>> s = s.collapse(field="category")
>>> pp(s.to_dict())
{'query': {'bool': {'filter': [{'term': {'color': 'red'}}]}},
 'collapse': {'field': 'category'}}
>>> s = s.filter("term", brand="something")
>>> pp(s.to_dict())
{'query': {'bool': {'filter': [{'term': {'color': 'red'}},
                               {'term': {'brand': 'something'}}]}}}

What is the expected behavior?

The _collapse property should be preserved when chaining additional methods after to the Search object.

What is your host/environment?

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
OpenSearch 2.6.0

Do you have any screenshots?

Not needed.

Do you have any additional context?

I think this bug was introduced during the implementation of collapse, because the _collapse property is not copied in the _clone method.

@Mdelaf Mdelaf added bug Something isn't working untriaged Need triage labels Jun 27, 2024
@saimedhi saimedhi removed the untriaged Need triage label Jun 27, 2024
@saimedhi
Copy link
Collaborator

Hello @Mdelaf, thank you for reporting this issue; would you be interested in contributing a fix, please?

@imvtsl
Copy link
Contributor

imvtsl commented Jun 29, 2024

@Mdelaf In case you don't want to work on the fix, I would be happy to pitch in and contribute to the fix. Please let us know if you are working on the fix.

@imvtsl
Copy link
Contributor

imvtsl commented Jul 5, 2024

Hello @saimedhi
@Mdelaf hasn't replied. I already waited a week now for @Mdelaf.
Do you mind if I go ahead and raise PR for the fix?

@saimedhi
Copy link
Collaborator

saimedhi commented Jul 6, 2024

Hello @saimedhi
@Mdelaf hasn't replied. I already waited a week now for @Mdelaf.
Do you mind if I go ahead and raise PR for the fix?

@imvtsl Please feel free to raise PR with fix. Thank you.

@imvtsl
Copy link
Contributor

imvtsl commented Jul 7, 2024

Thanks @saimedhi . I will raise a PR with fix.

@imvtsl
Copy link
Contributor

imvtsl commented Jul 9, 2024

I raised this PR for the fix.
@Mdelaf was right in his analysis that collapse property is not copied in the clone method.

@saimedhi
Copy link
Collaborator

saimedhi commented Jul 9, 2024

Resolved by PR #771

@saimedhi saimedhi closed this as completed Jul 9, 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

3 participants