Skip to content

Commit 6b04ee9

Browse files
authored
Merge pull request #227 from reportportal/develop
Release
2 parents 883d2f1 + cd64d72 commit 6b04ee9

File tree

16 files changed

+173
-15
lines changed

16 files changed

+173
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Added
5+
- Issue [#225](https://github.com/reportportal/client-Python/issues/225): JSON decoding error logging, by @HardNorth
6+
### Fixed
7+
- Issue [#226](https://github.com/reportportal/client-Python/issues/226): Logging batch flush on client close, by @HardNorth
8+
9+
## [5.5.3]
410
### Fixed
511
- Python 3.7 support, by @HardNorth
612
- Launch UUID attribute for AIO clients, by @HardNorth

reportportal_client/_internal/aio/tasks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
_T = TypeVar('_T')
2525

26-
2726
DEFAULT_TASK_TRIGGER_NUM: int = 10
2827
DEFAULT_TASK_TRIGGER_INTERVAL: float = 1.0
2928

reportportal_client/_internal/services/client_id.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from .constants import CLIENT_ID_PROPERTY, RP_FOLDER_PATH, \
2323
RP_PROPERTIES_FILE_PATH
2424

25-
2625
logger = logging.getLogger(__name__)
2726
logger.addHandler(logging.NullHandler())
2827

reportportal_client/_internal/services/client_id.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
from typing import Optional, Text
1515

16-
def _read_client_id() -> Optional[Text]:
17-
pass
1816

19-
def _store_client_id(client_id: Text) -> None:
20-
pass
17+
def _read_client_id() -> Optional[Text]: ...
2118

22-
def get_client_id() -> Text:
23-
pass
19+
20+
def _store_client_id(client_id: Text) -> None: ...
21+
22+
23+
def get_client_id() -> Text: ...

reportportal_client/_internal/services/statistics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import certifi
2323
import requests
2424

25-
from reportportal_client.helpers import get_package_parameters
2625
from reportportal_client._internal.services.client_id import get_client_id
2726
from reportportal_client._internal.services.constants import CLIENT_INFO, ENDPOINT
27+
from reportportal_client.helpers import get_package_parameters
2828

2929
logger = logging.getLogger(__name__)
3030

reportportal_client/_internal/static/defines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"""This module provides RP client static objects and variables."""
1515

1616
import aenum as enum
17-
from reportportal_client.helpers import ATTRIBUTE_LENGTH_LIMIT as ATTRIBUTE_LIMIT
1817

18+
from reportportal_client.helpers import ATTRIBUTE_LENGTH_LIMIT as ATTRIBUTE_LIMIT
1919

2020
RP_LOG_LEVELS = {
2121
60000: 'UNKNOWN',

reportportal_client/aio/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ def clone(self) -> 'AsyncRPClient':
924924

925925
async def close(self) -> None:
926926
"""Close current client connections."""
927+
await self.__client.log_batch(self._log_batcher.flush())
927928
await self.__client.close()
928929

929930

@@ -1307,6 +1308,7 @@ def log(self, time: str, message: str, level: Optional[Union[int, str]] = None,
13071308

13081309
def close(self) -> None:
13091310
"""Close current client connections."""
1311+
self.finish_tasks()
13101312
if self.own_client:
13111313
self.create_task(self.__client.close()).blocking_result()
13121314

reportportal_client/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ def clone(self) -> 'RPClient':
886886

887887
def close(self) -> None:
888888
"""Close current client connections."""
889+
self._log(self._log_batcher.flush())
889890
self.session.close()
890891

891892
def __getstate__(self) -> Dict[str, Any]:

reportportal_client/core/rp_responses.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import logging
2222
from json import JSONDecodeError
23-
from typing import Any, Optional, Generator, Mapping, Tuple
23+
from typing import Any, Optional, Generator, Mapping, Tuple, Union
2424

2525
from aiohttp import ClientResponse
2626
from requests import Response
@@ -41,6 +41,12 @@ def _iter_json_messages(json: Any) -> Generator[str, None, None]:
4141
yield message
4242

4343

44+
def _get_json_decode_error_message(response: Union[Response, ClientResponse]) -> str:
45+
status = getattr(response, 'status', getattr(response, 'status_code'))
46+
return f'Unable to decode JSON response, got {"passed" if response.ok else "failed"} ' \
47+
f'response with code "{status}" please check your endpoint configuration or API key'
48+
49+
4450
class RPResponse:
4551
"""Class representing ReportPortal API response."""
4652

@@ -82,7 +88,8 @@ def json(self) -> Any:
8288
if self.__json is NOT_SET:
8389
try:
8490
self.__json = self._resp.json()
85-
except (JSONDecodeError, TypeError):
91+
except (JSONDecodeError, TypeError) as exc:
92+
logger.error(_get_json_decode_error_message(self._resp), exc_info=exc)
8693
self.__json = None
8794
return self.__json
8895

@@ -149,7 +156,8 @@ async def json(self) -> Any:
149156
if self.__json is NOT_SET:
150157
try:
151158
self.__json = await self._resp.json()
152-
except (JSONDecodeError, TypeError):
159+
except (JSONDecodeError, TypeError) as exc:
160+
logger.error(_get_json_decode_error_message(self._resp), exc_info=exc)
153161
self.__json = None
154162
return self.__json
155163

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from setuptools import setup, find_packages
66

7-
__version__ = '5.5.3'
7+
__version__ = '5.5.4'
88

99
TYPE_STUBS = ['*.pyi']
1010

0 commit comments

Comments
 (0)