Add override for code generator to change indices.put_alias argument order (#804)

* Add currently-failing test to validate the original argument order

Signed-off-by: Jeppe Fihl-Pearson <jeppe@memrise.com>

* Add workaround for breaking API change inadvertently added in v2.7.0

Signed-off-by: Jeppe Fihl-Pearson <jeppe@memrise.com>

* Generate new version of the client code with the correct argument order

Signed-off-by: Jeppe Fihl-Pearson <jeppe@memrise.com>

---------

Signed-off-by: Jeppe Fihl-Pearson <jeppe@memrise.com>
This commit is contained in:
Jeppe Fihl-Pearson
2024-08-22 13:33:55 +01:00
committed by GitHub
parent b994dc4063
commit e26f3fc28c
7 changed files with 147 additions and 115 deletions
+1
View File
@@ -24,6 +24,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed the use of `minimum_should_match` with `Bool` to allow the use of string-based value (percent string, combination). ([#780](https://github.com/opensearch-project/opensearch-py/pull/780))
- Fixed incorrect `retry_on_conflict` type ([#795](https://github.com/opensearch-project/opensearch-py/pull/795))
### Updated APIs
- Updated opensearch-py APIs to reflect [opensearch-api-specification@b28c1cf](https://github.com/opensearch-project/opensearch-api-specification/commit/b28c1cfaf4a76d786c789929eaa7fabffd09cb99)
- Updated opensearch-py APIs to reflect [opensearch-api-specification@9d3bc34](https://github.com/opensearch-project/opensearch-api-specification/commit/9d3bc340ccd7d049e7d6e14a4aff2293780cb446)
### Security
### Dependencies
+57 -57
View File
@@ -852,63 +852,6 @@ class IndicesClient(NamespacedClient):
headers=headers,
)
@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"master_timeout",
"pretty",
"source",
"timeout",
)
async def put_alias(
self,
body: Any = None,
index: Any = None,
name: Any = None,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Creates or updates an alias.
:arg body: The settings for the alias, such as `routing` or
`filter`
:arg index: Comma-separated list of data streams or indices to
add. Supports wildcards (`*`). Wildcard patterns that match both data
streams and indices return an error.
:arg name: Alias to update. If the alias doesn't exist, the
request creates it. Index alias names support date math.
:arg cluster_manager_timeout: Operation timeout for connection
to cluster-manager node.
:arg error_trace: Whether to include the stack trace of returned
errors.
:arg filter_path: Comma-separated list of filters used to reduce
the response.
:arg human: Whether to return human readable values for
statistics.
:arg master_timeout (Deprecated: To promote inclusive language,
use 'cluster_manager_timeout' instead.): Period to wait for a connection
to the master node. If no response is received before the timeout
expires, the request fails and returns an error.
:arg pretty: Whether to pretty format the returned JSON
response.
:arg source: The URL-encoded request definition. Useful for
libraries that do not accept a request body for non-POST requests.
:arg timeout: Period to wait for a response. If no response is
received before the timeout expires, the request fails and returns an
error.
"""
return await self.transport.perform_request(
"PUT",
_make_path(index, "_alias", name),
params=params,
headers=headers,
body=body,
)
@query_params(
"allow_no_indices",
"error_trace",
@@ -2766,3 +2709,60 @@ class IndicesClient(NamespacedClient):
params=params,
headers=headers,
)
@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"master_timeout",
"pretty",
"source",
"timeout",
)
async def put_alias(
self,
index: Any = None,
name: Any = None,
body: Any = None,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Creates or updates an alias.
:arg body: The settings for the alias, such as `routing` or
`filter`
:arg index: Comma-separated list of data streams or indices to
add. Supports wildcards (`*`). Wildcard patterns that match both data
streams and indices return an error.
:arg name: Alias to update. If the alias doesn't exist, the
request creates it. Index alias names support date math.
:arg cluster_manager_timeout: Operation timeout for connection
to cluster-manager node.
:arg error_trace: Whether to include the stack trace of returned
errors.
:arg filter_path: Comma-separated list of filters used to reduce
the response.
:arg human: Whether to return human readable values for
statistics.
:arg master_timeout (Deprecated: To promote inclusive language,
use 'cluster_manager_timeout' instead.): Period to wait for a connection
to the master node. If no response is received before the timeout
expires, the request fails and returns an error.
:arg pretty: Whether to pretty format the returned JSON
response.
:arg source: The URL-encoded request definition. Useful for
libraries that do not accept a request body for non-POST requests.
:arg timeout: Period to wait for a response. If no response is
received before the timeout expires, the request fails and returns an
error.
"""
return await self.transport.perform_request(
"PUT",
_make_path(index, "_alias", name),
params=params,
headers=headers,
body=body,
)
+57 -57
View File
@@ -852,63 +852,6 @@ class IndicesClient(NamespacedClient):
headers=headers,
)
@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"master_timeout",
"pretty",
"source",
"timeout",
)
def put_alias(
self,
body: Any = None,
index: Any = None,
name: Any = None,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Creates or updates an alias.
:arg body: The settings for the alias, such as `routing` or
`filter`
:arg index: Comma-separated list of data streams or indices to
add. Supports wildcards (`*`). Wildcard patterns that match both data
streams and indices return an error.
:arg name: Alias to update. If the alias doesn't exist, the
request creates it. Index alias names support date math.
:arg cluster_manager_timeout: Operation timeout for connection
to cluster-manager node.
:arg error_trace: Whether to include the stack trace of returned
errors.
:arg filter_path: Comma-separated list of filters used to reduce
the response.
:arg human: Whether to return human readable values for
statistics.
:arg master_timeout (Deprecated: To promote inclusive language,
use 'cluster_manager_timeout' instead.): Period to wait for a connection
to the master node. If no response is received before the timeout
expires, the request fails and returns an error.
:arg pretty: Whether to pretty format the returned JSON
response.
:arg source: The URL-encoded request definition. Useful for
libraries that do not accept a request body for non-POST requests.
:arg timeout: Period to wait for a response. If no response is
received before the timeout expires, the request fails and returns an
error.
"""
return self.transport.perform_request(
"PUT",
_make_path(index, "_alias", name),
params=params,
headers=headers,
body=body,
)
@query_params(
"allow_no_indices",
"error_trace",
@@ -2766,3 +2709,60 @@ class IndicesClient(NamespacedClient):
params=params,
headers=headers,
)
@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"master_timeout",
"pretty",
"source",
"timeout",
)
def put_alias(
self,
index: Any = None,
name: Any = None,
body: Any = None,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Creates or updates an alias.
:arg body: The settings for the alias, such as `routing` or
`filter`
:arg index: Comma-separated list of data streams or indices to
add. Supports wildcards (`*`). Wildcard patterns that match both data
streams and indices return an error.
:arg name: Alias to update. If the alias doesn't exist, the
request creates it. Index alias names support date math.
:arg cluster_manager_timeout: Operation timeout for connection
to cluster-manager node.
:arg error_trace: Whether to include the stack trace of returned
errors.
:arg filter_path: Comma-separated list of filters used to reduce
the response.
:arg human: Whether to return human readable values for
statistics.
:arg master_timeout (Deprecated: To promote inclusive language,
use 'cluster_manager_timeout' instead.): Period to wait for a connection
to the master node. If no response is received before the timeout
expires, the request fails and returns an error.
:arg pretty: Whether to pretty format the returned JSON
response.
:arg source: The URL-encoded request definition. Useful for
libraries that do not accept a request body for non-POST requests.
:arg timeout: Period to wait for a response. If no response is
received before the timeout expires, the request fails and returns an
error.
"""
return self.transport.perform_request(
"PUT",
_make_path(index, "_alias", name),
params=params,
headers=headers,
body=body,
)
@@ -45,3 +45,8 @@ class TestIndices(OpenSearchTestCase):
self.assertRaises(ValueError, self.client.indices.exists, index=None)
self.assertRaises(ValueError, self.client.indices.exists, index=[])
self.assertRaises(ValueError, self.client.indices.exists, index="")
def test_create_alias(self) -> None:
self.client.indices.create("test-index")
self.client.indices.put_alias("test-index", "test-alias")
self.assert_url_called("PUT", "/test-index/_alias/test-alias")
+1 -1
View File
@@ -1,6 +1,6 @@
@query_params({{ api.query_params|map("tojson")|join(", ")}})
async def {{ api.name }}(self, {% include "func_params" %}) -> Any:
async def {{ api.name }}(self, {% block func_params %}{% include "func_params" %}{% endblock %}) -> Any:
"""
{% if api.description %}
{{ api.description|replace("\n", " ")|wordwrap(wrapstring="\n ") }}
@@ -0,0 +1,2 @@
{% extends "base" %}
{% block func_params %}{% include "overrides/indices/put_alias-func_params" %}{% endblock %}
@@ -0,0 +1,24 @@
{# Work around for https://github.com/opensearch-project/opensearch-py/issues/803 #}
{% set first_params = ["index", "name"] %}
{% for p, info in api.all_parts.items() %}
{% if info.required %}{{ p }}: {{ info.type }}, {% endif %}
{% endfor %}
{% for p, info in api.all_parts.items() if p in first_params %}
{% if not info.type == 'Any' %}{{ p }}: Optional[{{ info.type }}]=None, {% endif %}
{% if info.type == 'Any' %}{{ p }}: {{ info.type }}=None, {% endif %}
{% endfor %}
{% if api.body %}
body{% if not api.body.required %}: Any=None{% else %}: Any{% endif %},
{% endif %}
{% for p, info in api.all_parts.items() if p not in first_params %}
{% if not info.required and not info.type == 'Any' %}{{ p }}: Optional[{{ info.type }}]=None, {% endif %}
{% if not info.required and info.type == 'Any' %}{{ p }}: {{ info.type }}=None, {% endif %}
{% endfor %}
params: Any=None,
headers: Any=None,