diff --git a/swh/core/api/__init__.py b/swh/core/api/__init__.py --- a/swh/core/api/__init__.py +++ b/swh/core/api/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2020 The Software Heritage developers +# Copyright (C) 2015-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -7,7 +7,6 @@ import functools import inspect import logging -import pickle from typing import ( Any, Callable, @@ -325,36 +324,18 @@ exception = None - # TODO: only old servers send pickled error; stop trying to unpickle - # after they are all upgraded - try: - if status_class == 4: - data = self._decode_response(response, check_status=False) - if isinstance(data, dict): - # TODO: remove "exception" key check once all servers - # are using new schema - exc_data = data["exception"] if "exception" in data else data - for exc_type in self.reraise_exceptions: - if exc_type.__name__ == exc_data["type"]: - exception = exc_type(*exc_data["args"]) - break - else: - exception = RemoteException(payload=exc_data, response=response) - else: - exception = pickle.loads(data) - - elif status_class == 5: - data = self._decode_response(response, check_status=False) - if "exception_pickled" in data: - exception = pickle.loads(data["exception_pickled"]) - else: - # TODO: remove "exception" key check once all servers - # are using new schema - exc_data = data["exception"] if "exception" in data else data - exception = RemoteException(payload=exc_data, response=response) - - except (TypeError, pickle.UnpicklingError): - raise RemoteException(payload=data, response=response) + if status_class == 4: + exc_data = self._decode_response(response, check_status=False) + for exc_type in self.reraise_exceptions: + if exc_type.__name__ == exc_data["type"]: + exception = exc_type(*exc_data["args"]) + break + else: + exception = RemoteException(payload=exc_data, response=response) + + elif status_class == 5: + exc_data = self._decode_response(response, check_status=False) + exception = RemoteException(payload=exc_data, response=response) if exception: raise exception from None diff --git a/swh/core/api/tests/test_rpc_client.py b/swh/core/api/tests/test_rpc_client.py --- a/swh/core/api/tests/test_rpc_client.py +++ b/swh/core/api/tests/test_rpc_client.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2019 The Software Heritage developers +# Copyright (C) 2018-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -110,13 +110,11 @@ assert str(exc_info.value.args[0]) == error_message -def _exception_response(exception, status_code, old_exception_schema=False): +def _exception_response(exception, status_code): def callback(request, context): assert request.headers["Content-Type"] == "application/x-msgpack" context.headers["Content-Type"] = "application/x-msgpack" exc_dict = exception_to_dict(exception) - if old_exception_schema: - exc_dict = {"exception": exc_dict} context.content = msgpack_dumps(exc_dict) context.status_code = status_code return context.content @@ -124,8 +122,7 @@ return callback -@pytest.mark.parametrize("old_exception_schema", [False, True]) -def test_client_reraise_exception(rpc_client, requests_mock, old_exception_schema): +def test_client_reraise_exception(rpc_client, requests_mock): """ Exception caught server-side and whitelisted will be raised again client-side. """ @@ -137,7 +134,6 @@ content=_exception_response( exception=ReraiseException(error_message), status_code=400, - old_exception_schema=old_exception_schema, ), ) @@ -147,18 +143,8 @@ assert str(exc_info.value) == error_message -@pytest.mark.parametrize( - "status_code, old_exception_schema", - [ - (400, False), - (500, False), - (400, True), - (500, True), - ], -) -def test_client_raise_remote_exception( - rpc_client, requests_mock, status_code, old_exception_schema -): +@pytest.mark.parametrize("status_code", [400, 500]) +def test_client_raise_remote_exception(rpc_client, requests_mock, status_code): """ Exception caught server-side and not whitelisted will be wrapped and raised as a RemoteException client-side. @@ -171,7 +157,6 @@ content=_exception_response( exception=Exception(error_message), status_code=status_code, - old_exception_schema=old_exception_schema, ), )