[PR #21208] [CLOSED] fix: use keyword args for IndicesClient.refresh() (opensearch-py >= 3.0.0) #25967

Closed
opened 2026-04-20 06:14:27 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21208
Author: @veeceey
Created: 2/6/2026
Status: Closed

Base: mainHead: fix/issue-20649-opensearch-refresh-kwarg


📝 Commits (1)

  • 39ee0a3 fix: use keyword args for IndicesClient.refresh() (opensearch-py >= 3.0.0)

📊 Changes

2 files changed (+345 additions, -3 deletions)

View changed files

📝 backend/open_webui/retrieval/vector/dbs/opensearch.py (+3 -3)
backend/open_webui/test/apps/webui/routers/test_opensearch.py (+342 -0)

📄 Description

Summary

Fixes #20649

In opensearch-py >= 3.0.0, all auto-generated API methods switched to keyword-only arguments. The three calls to IndicesClient.refresh() in the OpenSearch vector DB client were passing the index name as a positional argument, causing:

TypeError: IndicesClient.refresh() takes 1 positional argument but 2
positional arguments (and 2 keyword-only arguments) were given

This made it impossible to add documents to a knowledge base when using OpenSearch as the vector DB backend.

Changes

backend/open_webui/retrieval/vector/dbs/opensearch.py - Changed all 3 call sites from positional to keyword argument:

# Before (broken with opensearch-py >= 3.0.0):
self.client.indices.refresh(self._get_index_name(collection_name))

# After (compatible with all versions):
self.client.indices.refresh(index=self._get_index_name(collection_name))

Affected methods: insert() (line 214), upsert() (line 237), delete() (line 266).

backend/open_webui/test/apps/webui/routers/test_opensearch.py - Added 9 unit tests that:

  • Mock the opensearch-py 3.0.0 keyword-only signature enforcement
  • Verify all 3 refresh() call sites use index= keyword argument
  • Demonstrate the exact TypeError from the issue is prevented by the fix
  • Audit all other opensearch-py API calls for keyword arg compliance

Test evidence

All 9 tests PASS with the fix applied:

$ python3 -m pytest backend/open_webui/test/apps/webui/routers/test_opensearch.py -v

backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_insert_calls_refresh_with_keyword_arg PASSED [ 11%]
backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_upsert_calls_refresh_with_keyword_arg PASSED [ 22%]
backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_delete_by_ids_calls_refresh_with_keyword_arg PASSED [ 33%]
backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_delete_by_filter_calls_refresh_with_keyword_arg PASSED [ 44%]
backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_refresh_raises_typeerror_with_positional_arg_on_3x PASSED [ 55%]
backend/...test_opensearch.py::TestOpenSearchAllApiCallsUseKeywordArgs::test_has_collection_uses_keyword_args PASSED [ 66%]
backend/...test_opensearch.py::TestOpenSearchAllApiCallsUseKeywordArgs::test_delete_collection_uses_keyword_args PASSED [ 77%]
backend/...test_opensearch.py::TestOpenSearchAllApiCallsUseKeywordArgs::test_search_uses_keyword_args PASSED [ 88%]
backend/...test_opensearch.py::TestOpenSearchAllApiCallsUseKeywordArgs::test_reset_uses_keyword_args PASSED [100%]

============================== 9 passed in 0.03s ===============================

Key test FAILS on the unfixed (original) code:

To verify the tests correctly detect the bug, I reverted the fix and ran the critical test:

$ git stash  # revert to unfixed code
$ python3 -m pytest ...::test_refresh_raises_typeerror_with_positional_arg_on_3x -v

FAILED [100%]
E  TypeError: refresh_keyword_only() takes 0 positional arguments but 1 was given

$ git stash pop  # restore the fix

This confirms the test correctly reproduces the exact TypeError from issue #20649 on unfixed code, and the fix resolves it.

Test plan

  • All 9 unit tests pass with the fix applied
  • Tests correctly FAIL when reverting to the original (broken) code
  • Tests mock opensearch-py 3.0.0 keyword-only enforcement without requiring an actual OpenSearch cluster
  • Tests load only the opensearch.py module in isolation (no full app dependency tree needed)
  • Verified all other opensearch-py API calls in the file already use keyword arguments
  • Using index= keyword arg is backward-compatible with opensearch-py < 3.0.0

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/21208 **Author:** [@veeceey](https://github.com/veeceey) **Created:** 2/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/issue-20649-opensearch-refresh-kwarg` --- ### 📝 Commits (1) - [`39ee0a3`](https://github.com/open-webui/open-webui/commit/39ee0a3fb0ee79da21a596325566a305ff452131) fix: use keyword args for IndicesClient.refresh() (opensearch-py >= 3.0.0) ### 📊 Changes **2 files changed** (+345 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/retrieval/vector/dbs/opensearch.py` (+3 -3) ➕ `backend/open_webui/test/apps/webui/routers/test_opensearch.py` (+342 -0) </details> ### 📄 Description ## Summary Fixes #20649 In `opensearch-py >= 3.0.0`, all auto-generated API methods switched to **keyword-only arguments**. The three calls to `IndicesClient.refresh()` in the OpenSearch vector DB client were passing the index name as a **positional argument**, causing: ``` TypeError: IndicesClient.refresh() takes 1 positional argument but 2 positional arguments (and 2 keyword-only arguments) were given ``` This made it **impossible to add documents to a knowledge base** when using OpenSearch as the vector DB backend. ## Changes **`backend/open_webui/retrieval/vector/dbs/opensearch.py`** - Changed all 3 call sites from positional to keyword argument: ```python # Before (broken with opensearch-py >= 3.0.0): self.client.indices.refresh(self._get_index_name(collection_name)) # After (compatible with all versions): self.client.indices.refresh(index=self._get_index_name(collection_name)) ``` Affected methods: `insert()` (line 214), `upsert()` (line 237), `delete()` (line 266). **`backend/open_webui/test/apps/webui/routers/test_opensearch.py`** - Added 9 unit tests that: - Mock the opensearch-py 3.0.0 keyword-only signature enforcement - Verify all 3 `refresh()` call sites use `index=` keyword argument - Demonstrate the exact TypeError from the issue is prevented by the fix - Audit all other opensearch-py API calls for keyword arg compliance ## Test evidence ### All 9 tests PASS with the fix applied: ``` $ python3 -m pytest backend/open_webui/test/apps/webui/routers/test_opensearch.py -v backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_insert_calls_refresh_with_keyword_arg PASSED [ 11%] backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_upsert_calls_refresh_with_keyword_arg PASSED [ 22%] backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_delete_by_ids_calls_refresh_with_keyword_arg PASSED [ 33%] backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_delete_by_filter_calls_refresh_with_keyword_arg PASSED [ 44%] backend/...test_opensearch.py::TestOpenSearchRefreshKeywordArgs::test_refresh_raises_typeerror_with_positional_arg_on_3x PASSED [ 55%] backend/...test_opensearch.py::TestOpenSearchAllApiCallsUseKeywordArgs::test_has_collection_uses_keyword_args PASSED [ 66%] backend/...test_opensearch.py::TestOpenSearchAllApiCallsUseKeywordArgs::test_delete_collection_uses_keyword_args PASSED [ 77%] backend/...test_opensearch.py::TestOpenSearchAllApiCallsUseKeywordArgs::test_search_uses_keyword_args PASSED [ 88%] backend/...test_opensearch.py::TestOpenSearchAllApiCallsUseKeywordArgs::test_reset_uses_keyword_args PASSED [100%] ============================== 9 passed in 0.03s =============================== ``` ### Key test FAILS on the unfixed (original) code: To verify the tests correctly detect the bug, I reverted the fix and ran the critical test: ``` $ git stash # revert to unfixed code $ python3 -m pytest ...::test_refresh_raises_typeerror_with_positional_arg_on_3x -v FAILED [100%] E TypeError: refresh_keyword_only() takes 0 positional arguments but 1 was given $ git stash pop # restore the fix ``` This confirms the test correctly reproduces the exact `TypeError` from issue #20649 on unfixed code, and the fix resolves it. ## Test plan - [x] All 9 unit tests pass with the fix applied - [x] Tests correctly FAIL when reverting to the original (broken) code - [x] Tests mock opensearch-py 3.0.0 keyword-only enforcement without requiring an actual OpenSearch cluster - [x] Tests load only the opensearch.py module in isolation (no full app dependency tree needed) - [x] Verified all other opensearch-py API calls in the file already use keyword arguments - [x] Using `index=` keyword arg is backward-compatible with opensearch-py < 3.0.0 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 06:14:27 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#25967