From e8b93b8e3a73c1689eda025b9e2f1f04a250c970 Mon Sep 17 00:00:00 2001 From: Francis CLAIRICIA-ROSE-CLAIRE-JOSEPHINE Date: Thu, 23 Nov 2023 08:50:50 +0100 Subject: [PATCH] [FIX] IncrementalDeserializeError.remaining_data is no longer reset --- src/easynetwork/lowlevel/_stream.py | 4 +--- src/easynetwork/protocol.py | 3 +-- tests/unit_test/test_protocol.py | 1 + tests/unit_test/test_tools/test_stream.py | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/easynetwork/lowlevel/_stream.py b/src/easynetwork/lowlevel/_stream.py index 33c735ca..b5c4e7cf 100644 --- a/src/easynetwork/lowlevel/_stream.py +++ b/src/easynetwork/lowlevel/_stream.py @@ -146,9 +146,7 @@ def __next__(self) -> _ReceivedPacketT: packet, remaining = exc.value remaining = _ensure_bytes(remaining) except StreamProtocolParseError as exc: - remaining, exc.remaining_data = exc.remaining_data, b"" - remaining = _ensure_bytes(remaining) - self.__b = remaining + self.__b = _ensure_bytes(exc.remaining_data) raise except Exception as exc: raise RuntimeError("protocol.build_packet_from_chunks() crashed") from exc diff --git a/src/easynetwork/protocol.py b/src/easynetwork/protocol.py index 3db69213..19b6f3e0 100644 --- a/src/easynetwork/protocol.py +++ b/src/easynetwork/protocol.py @@ -191,8 +191,7 @@ def build_packet_from_chunks(self) -> Generator[None, bytes, tuple[_ReceivedPack try: packet, remaining_data = yield from self.__serializer.incremental_deserialize() except IncrementalDeserializeError as exc: - remaining_data, exc.remaining_data = exc.remaining_data, b"" - raise StreamProtocolParseError(remaining_data, exc) from exc + raise StreamProtocolParseError(exc.remaining_data, exc) from exc except DeserializeError as exc: raise RuntimeError("DeserializeError raised instead of IncrementalDeserializeError") from exc diff --git a/tests/unit_test/test_protocol.py b/tests/unit_test/test_protocol.py index 3ac9cc94..3b4e9903 100644 --- a/tests/unit_test/test_protocol.py +++ b/tests/unit_test/test_protocol.py @@ -363,6 +363,7 @@ def test____build_packet_from_chunks____deserialize_error( mock_convert_func.assert_not_called() assert isinstance(exception.error, IncrementalDeserializeError) assert exception.remaining_data is mocker.sentinel.chunk + assert exception.error.remaining_data is mocker.sentinel.chunk assert isinstance(exception.__cause__, IncrementalDeserializeError) def test____build_packet_from_chunks____wrong_deserialize_error( diff --git a/tests/unit_test/test_tools/test_stream.py b/tests/unit_test/test_tools/test_stream.py index 54ed0c76..9c7dac0d 100644 --- a/tests/unit_test/test_tools/test_stream.py +++ b/tests/unit_test/test_tools/test_stream.py @@ -441,7 +441,7 @@ def side_effect() -> Generator[None, bytes, tuple[Any, bytes]]: # Assert mock_build_packet_from_chunks_func.assert_called_once_with() assert consumer.get_buffer() == b"World" - assert exception.remaining_data == b"" + assert exception.remaining_data == b"World" def test____next____generator_did_not_yield( self,