Skip to content

Commit

Permalink
Fixed ignore argument in perform request in Transport and AsyncTransport
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Borisevich <andreyborisevichleti@gmail.com>
  • Loading branch information
borisevich-a-v committed Aug 26, 2024
1 parent 9fb27b8 commit 7d8b3e6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion opensearchpy/_async/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ async def perform_request(
await self._async_call()

method, params, body, ignore, timeout = self._resolve_request_args(
method, params, body
method, params, body, ignore, timeout
)

for attempt in range(self.max_retries + 1):
Expand Down
7 changes: 4 additions & 3 deletions opensearchpy/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def perform_request(
will be extracted from `params`
"""
method, params, body, ignore, timeout = self._resolve_request_args(
method, params, body, timeout
method, params, body, ignore, timeout
)

for attempt in range(self.max_retries + 1):
Expand Down Expand Up @@ -480,6 +480,7 @@ def _resolve_request_args(
method: str,
params: Any,
body: Any,
ignore: Collection[int],
timeout: Optional[Union[int, float]],
) -> Any:
"""Resolves parameters for .perform_request()"""
Expand All @@ -506,11 +507,11 @@ def _resolve_request_args(
# bytes/str - no need to re-encode
pass

ignore = ()
if params:
if not timeout:
timeout = params.pop("request_timeout", None) or params.pop("timeout", None)
ignore = params.pop("ignore", ())
if not ignore:
ignore = params.pop("ignore", ())
if isinstance(ignore, int):
ignore = (ignore,)

Expand Down
14 changes: 14 additions & 0 deletions test_opensearchpy/test_async/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ async def test_opaque_id(self) -> None:
"headers": {"x-opaque-id": "request-1"},
} == t.get_connection().calls[1][1]

async def test_perform_request_all_arguments_passed_correctly(self) -> None:
t: Any = AsyncTransport([{}], connection_class=DummyConnection)
method, url, params, body = "GET", "/test_url", {"params": "test"}, "test_body"
timeout, ignore, headers = 11, ("ignore",), {"h": "test"}

await t.perform_request(method, url, params, body, timeout, ignore, headers)

assert t.get_connection().calls == [
(
(method, url, params, body.encode()),
{"headers": headers, "ignore": ignore, "timeout": timeout}
)
]

async def test_request_with_custom_user_agent_header(self) -> None:
t: Any = AsyncTransport([{}], connection_class=DummyConnection)

Expand Down
17 changes: 17 additions & 0 deletions test_opensearchpy/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,23 @@ def test_add_connection(self) -> None:
"http://google.com:1234", t.connection_pool.connections[1].host
)

def test_perform_request_all_arguments_passed_correctly(self) -> None:
t: Any = Transport([{}], connection_class=DummyConnection)
method, url, params, body = "GET", "/test_url", {"params": "test"}, "test_body"
timeout, ignore, headers = 11, ("ignore",), {"h": "test"}

t.perform_request(method, url, params, body, timeout, ignore, headers)

self.assertEqual(
t.get_connection().calls,
[
(
(method, url, params, body.encode()),
{"headers": headers, "ignore": ignore, "timeout": timeout}
)
]
)

def test_request_will_fail_after_x_retries(self) -> None:
t: Any = Transport(
[{"exception": ConnectionError(None, "abandon ship", Exception())}],
Expand Down

0 comments on commit 7d8b3e6

Please sign in to comment.