Skip to content

fix: prevent double slashes in AliasGetReq path when Indices is empty - #802

Closed
anzzyspeaksgit wants to merge 1 commit into
opensearch-project:mainfrom
anzzyspeaksgit:fix/issue-617
Closed

fix: prevent double slashes in AliasGetReq path when Indices is empty#802
anzzyspeaksgit wants to merge 1 commit into
opensearch-project:mainfrom
anzzyspeaksgit:fix/issue-617

Conversation

@anzzyspeaksgit

Copy link
Copy Markdown

Problem

When calling AliasGetReq without specifying Indices (or providing an empty Indices array/slice), the resulting API path incorrectly contains a double slash.
For example, it might produce //_alias/test-alias instead of /_alias/test-alias. This double slash causes issues for proxies or when interacting with some clusters, such as Aiven where this causes failures (see #617).

Solution

I modified the GetRequest function in opensearchapi/api_indices-alias.go to conditionally append the initial / and indices string only if indices is not empty. If indices is empty, it appends only /_alias/ and the aliases name(s), ensuring the URL path is valid (e.g. /_alias/test-alias).

Testing

  • Verified via make test that all existing tests pass correctly.

Closes #617

@codecov

codecov Bot commented Mar 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.13%. Comparing base (9273eff) to head (d516557).

Files with missing lines Patch % Lines
opensearchapi/api_indices-alias.go 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #802      +/-   ##
==========================================
+ Coverage   72.05%   72.13%   +0.07%     
==========================================
  Files         427      427              
  Lines       15568    15571       +3     
==========================================
+ Hits        11218    11232      +14     
+ Misses       2668     2658      -10     
+ Partials     1682     1681       -1     
Flag Coverage Δ
integration 65.91% <66.66%> (+0.04%) ⬆️
unit 42.57% <0.00%> (+0.03%) ⬆️

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.08% <66.66%> (-1.92%) ⬇️

... and 4 files with indirect coverage changes

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

@sean-

sean- commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

There's also a fix posted for this in #804 , too.

@sean-

sean- commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the fix, @anzzyspeaksgit. Just to give you a status update: the underlying bug (#617) was fixed by #804 (merged 2026-05-28), which moved URL-path construction into a generated internal/path package. The new IndicesGetAliasPath builder uses hasNonEmpty() and writeSegments() helpers that silently skip empty strings, so AliasGetReq{Alias: []string{"test-alias"}} now produces /_alias/test-alias correctly.

I'd like to close this PR as resolved by #804. Could you verify the current behavior on main matches what you needed? If you find any case still producing double slashes, please open a new issue with a reproducer and we'll dig in.

Thanks again for the contribution.

@sean- sean- closed this Jun 8, 2026
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] Wrong request path computed in AliasGetReq when no indices are specified

2 participants