Skip to content

fix(api): alias api creates index when index name is nill #705

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

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

Conversation

rootxrishabh
Copy link

@rootxrishabh rootxrishabh commented May 27, 2025

Description

When Alias PUT api is called with an empty index name i.e "", the BuildRequest function parses characters after the double quote and before the next / as hostname for the request i.e _alias and request becomes https://localhost:9200/{aliasname} -H _alias -XPUT which actually creates an index.

The fix returns an error when a nil index is passed.

Note -
This is intended to be a temporary fix, however a better fix would be to parse the complete URL i.e instead of creating http request just with path parameters (i.e /<target>/_alias/<alias-name>) at BuildRequest, it would be better to provide the complete URL (i.e https://localhost:9200/<target>/_alias/<alias-name>). This however, requires a redesign of the API system.

Issues Resolved

#650

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 May 27, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 52.82%. Comparing base (06a6dc8) to head (0973c7f).
Report is 99 commits behind head on main.

Files with missing lines Patch % Lines
opensearchapi/api_indices-alias.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #705      +/-   ##
==========================================
- Coverage   57.29%   52.82%   -4.47%     
==========================================
  Files         315      375      +60     
  Lines        9823    11589    +1766     
==========================================
+ Hits         5628     6122     +494     
- Misses       2902     3998    +1096     
- Partials     1293     1469     +176     
Flag Coverage Δ
integration 52.82% <0.00%> (+1.98%) ⬆️
unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
opensearchapi/api_indices-alias.go 97.14% <0.00%> (-2.86%) ⬇️

... and 112 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rootxrishabh
Copy link
Author

@dblock @Jakob3xD, this PR is a quick fix to the attached issue. I hope the PR description explains the root cause. If not, I'd be happy to clarify.

@Jakob3xD
Copy link
Collaborator

I am not sure yet how I think about it. I generally understand that you want to avoid users of the lib from running into errors or wrong behaviours. But I personally don't think that the lib is responsible for this, as there are many more cases where users can run into such errors or wrong behaviours. Moreover, such special error prevention is harder to handle in code generation. What do you think @dblock ?

@dblock
Copy link
Member

dblock commented May 29, 2025

This fix could be fine, but it needs a test.

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.

3 participants