Skip to content

[Backport 7.x] Fix Connection.log_*() body parameter type #1395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions elasticsearch/connection/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ class Connection(object):
method: str,
full_url: str,
path: str,
body: str,
body: Optional[bytes],
status_code: int,
response: bytes,
response: str,
duration: float,
) -> None: ...
def log_request_fail(
self,
method: str,
full_url: str,
path: str,
body: str,
body: Optional[bytes],
duration: float,
status_code: Optional[int] = ...,
response: Optional[bytes] = ...,
response: Optional[str] = ...,
exception: Optional[Exception] = ...,
) -> None: ...
def _raise_error(self, status_code: int, raw_data: str) -> NoReturn: ...
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/connection/http_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def perform_request(
method,
url,
prepared_request.path_url,
body,
orig_body,
time.time() - start,
exception=e,
)
Expand Down
15 changes: 15 additions & 0 deletions test_elasticsearch/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from requests.auth import AuthBase
from platform import python_version

import pytest

from elasticsearch.exceptions import (
TransportError,
ConflictError,
Expand Down Expand Up @@ -754,6 +756,19 @@ def test_uncompressed_body_logged(self, logger):
self.assertEqual('> {"example": "body"}', req[0][0] % req[0][1:])
self.assertEqual("< {}", resp[0][0] % resp[0][1:])

con = self._get_mock_connection(
connection_params={"http_compress": True},
status_code=500,
response_body=b'{"hello":"world"}',
)
with pytest.raises(TransportError):
con.perform_request("GET", "/", body=b'{"example": "body2"}')

self.assertEqual(4, logger.debug.call_count)
_, _, req, resp = logger.debug.call_args_list
self.assertEqual('> {"example": "body2"}', req[0][0] % req[0][1:])
self.assertEqual('< {"hello":"world"}', resp[0][0] % resp[0][1:])

def test_defaults(self):
con = self._get_mock_connection()
request = self._get_request(con, "GET", "/")
Expand Down