diff --git a/haystack/dataclasses/byte_stream.py b/haystack/dataclasses/byte_stream.py index 9dca4d9697..43df1b734b 100644 --- a/haystack/dataclasses/byte_stream.py +++ b/haystack/dataclasses/byte_stream.py @@ -68,5 +68,5 @@ def __str__(self) -> str: """ Returns a string representation of the ByteStream, truncating the data to 1KB. """ - truncated = self.data[:1021] + b"..." if len(self.data) > 1024 else self.data + truncated = self.data[:1024] + b"..." if len(self.data) > 1024 else self.data return f"ByteStream(data={truncated!r}, mime_type={self.mime_type!r}, meta={self.meta!r})" diff --git a/test/dataclasses/test_byte_stream.py b/test/dataclasses/test_byte_stream.py index 574f1671bf..46c394a23c 100644 --- a/test/dataclasses/test_byte_stream.py +++ b/test/dataclasses/test_byte_stream.py @@ -71,3 +71,10 @@ def test_to_file(tmp_path, request): ByteStream(test_str.encode()).to_file(test_path) with open(test_path, "rb") as fd: assert fd.read().decode() == test_str + + +def test_str_truncation(): + test_str = "1234567890" * 1000 + b = ByteStream.from_string(test_str, mime_type="text/plain", meta={"foo": "bar"}) + string_repr = str(b) + assert len(string_repr) < 1200