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

Ignore name of index when fetching settings #823

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tienne-B
Copy link

Description

This commit fixes a situation where an index cannot be updated through this client as the index is aliased, with the client pointing to the alias.

As the GET /<index>/_settings request will only ever return the settings for the specified index (through the alias), it would only have one key, so the name of the key would not matter. We can pop the key to get the settings object for the index through the alias.

Describe what this change achieves.

Issues Resolved

Closes #822

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

Attention: Patch coverage is 18.18182% with 9 lines in your changes missing coverage. Please review.

Project coverage is 70.29%. Comparing base (ba715b9) to head (7da15f6).
Report is 59 commits behind head on main.

Files with missing lines Patch % Lines
opensearchpy/_async/helpers/index.py 20.00% 4 Missing ⚠️
opensearchpy/helpers/index.py 20.00% 4 Missing ⚠️
opensearchpy/helpers/test.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #823      +/-   ##
==========================================
- Coverage   71.95%   70.29%   -1.66%     
==========================================
  Files          91      113      +22     
  Lines        8001     8881     +880     
==========================================
+ Hits         5757     6243     +486     
- Misses       2244     2638     +394     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the value of _name vs. what it is after the change here?
Can you please add a test?

@tienne-B tienne-B force-pushed the patch-1 branch 2 times, most recently from 263b708 to 2ed7b6e Compare September 18, 2024 16:43
@tienne-B
Copy link
Author

Thank you @dblock for your quick response! The value of removing self._name is that saving an index previously wouldn't work if OS-py accesses it through an alias (and using an alias seems to be a good practice for downtime prevention). All the requests that are triggered by the .save() method can work transparently through an index, however, when making the GET /<alias>/_settings request, the dict response key is the name of the true index, rather than the alias. This causes the KeyError. However, the data we're extracting doesn't depend on the name, so it'd be safe to disregard and pop the key/value.

If it's wanted, I could add a check that the alias only points to one index to raise a more specific error. Would that be appreciated?

I've added a test, but I'm a little skeptical of the coverage report as it's based off a 6-month-old commit.

Thank you!

@dblock
Copy link
Member

dblock commented Sep 19, 2024

If it's wanted, I could add a check that the alias only points to one index to raise a more specific error. Would that be appreciated?

Possibly, but doesn't have to block this PR. Give it a shot after I merge this!

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all makes sense.

I think you have to do the same for the async code (see https://github.com/opensearch-project/opensearch-py/blob/main/opensearchpy/_async/helpers/index.py#L308). Add a test for that too.

This commit fixes a situation where an index cannot be updated through this client as the index is aliased, with the client pointing to the alias.

As the `GET /<index>/_settings` request will only ever return the settings for the specified index (through the alias), it would only have one key, so the name of the key would not matter. We can pop the key to get the settings object for the index through the alias.

Signed-off-by: Étienne Beaulé <beauleetienne0@gmail.com>
@tienne-B
Copy link
Author

I've added support for async, the checks for multiple indices, and testing for these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Cannot update aliased index through Index.save()
2 participants