You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This means that if a 404 is returned because a resource does not exist, then an error is raised because of the response.raise_for_status(). This causes other code to fail as well. For example this piece (in _async.client._base.py):
meta, resp_body=awaitself.transport.perform_request(
method,
target,
headers=request_headers,
body=body,
request_timeout=self._request_timeout,
max_retries=self._max_retries,
retry_on_status=self._retry_on_status,
retry_on_timeout=self._retry_on_timeout,
client_meta=self._client_meta,
otel_span=otel_span,
)
# HEAD with a 404 is returned as a normal response# since this is used as an 'exists' functionality.ifnot (method=="HEAD"andmeta.status==404) and (
not200<=meta.status<299and (
self._ignore_statusisDEFAULTorself._ignore_statusisNoneormeta.statusnotinself._ignore_status
)
):
message=str(resp_body)
# If the response is an error response try parsing# the raw Elasticsearch error before raising.ifisinstance(resp_body, dict):
try:
error=resp_body.get("error", message)
ifisinstance(error, dict) and"type"inerror:
error=error["type"]
message=errorexcept (ValueError, KeyError, TypeError):
passraiseHTTP_EXCEPTIONS.get(meta.status, ApiError)(
message=message, meta=meta, body=resp_body
)
The mentioned functionality (client.indices.exists(), client.indices.alias_exists(), client.get()) then stops working as expected. The fix seems easy:
Thanks for the report @Thijsvandepoll! Is your fix simply to stop raising for status? Difficult to tell like this. Would you be interested in opening a pull request so that it can be included in 8.15?
The Sync/Async Elasticsearch client relies on 404 status codes for some of it's functionality. Some examples are:
client.indices.exists()
client.indices.alias_exists()
, orclient.get()
The current implementation of the
HttpxAsyncHttpNode
is:This means that if a 404 is returned because a resource does not exist, then an error is raised because of the
response.raise_for_status()
. This causes other code to fail as well. For example this piece (in_async.client._base.py
):The mentioned functionality (
client.indices.exists()
,client.indices.alias_exists()
,client.get()
) then stops working as expected. The fix seems easy:The text was updated successfully, but these errors were encountered: