From 8c5cd0184901df89eceef86605ccc14a6f133185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Beaul=C3=A9?= Date: Fri, 15 Aug 2025 08:44:50 -0400 Subject: [PATCH] Pass through index aliases when checking if index closed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Étienne Beaulé --- CHANGELOG.md | 1 + opensearchpy/_async/helpers/index.py | 7 ++++++- opensearchpy/helpers/index.py | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8596937e2..73be69f08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Deprecated ### Removed ### Fixed +- Fix `Index.is_closed` not passing through aliases to the underlying index, preventing saving ([941](https://github.com/opensearch-project/opensearch-py/pull/941)) ### Security ### Dependencies - Bumps `aiohttp` from >=3.9.4,<4 to >=3.10.11,<4 ([#920](https://github.com/opensearch-project/opensearch-py/pull/920)) diff --git a/opensearchpy/_async/helpers/index.py b/opensearchpy/_async/helpers/index.py index 68da05333..8475684dc 100644 --- a/opensearchpy/_async/helpers/index.py +++ b/opensearchpy/_async/helpers/index.py @@ -288,7 +288,12 @@ async def is_closed(self, using: Any = None) -> Any: state = await (await self._get_connection(using)).cluster.state( index=self._name, metric="metadata" ) - return state["metadata"]["indices"][self._name]["state"] == "close" + index_name = ( + next(iter(state["metadata"]["indices"].keys())) + if len(state["metadata"]["indices"].keys()) == 1 + else self._name + ) + return state["metadata"]["indices"][index_name]["state"] == "close" async def save(self, using: Any = None) -> Any: """ diff --git a/opensearchpy/helpers/index.py b/opensearchpy/helpers/index.py index bb1569a49..4200317c3 100644 --- a/opensearchpy/helpers/index.py +++ b/opensearchpy/helpers/index.py @@ -309,7 +309,12 @@ def is_closed(self, using: Optional[OpenSearch] = None) -> Any: state = self._get_connection(using).cluster.state( index=self._name, metric="metadata" ) - return state["metadata"]["indices"][self._name]["state"] == "close" + index_name = ( + next(iter(state["metadata"]["indices"].keys())) + if len(state["metadata"]["indices"].keys()) == 1 + else self._name + ) + return state["metadata"]["indices"][index_name]["state"] == "close" def save(self, using: Optional[OpenSearch] = None) -> Any: """