From 2ddafe728ebb65ad5bdd9fd9500a9212d3d094c3 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 12 Aug 2025 16:38:18 -0700 Subject: [PATCH] thumbnail: Avoid BytesIO.getbuffer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems to cause ‘BufferError: Existing exports of data: object cannot be re-sized’ on Python 3.13. Signed-off-by: Anders Kaseorg --- zerver/worker/thumbnail.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zerver/worker/thumbnail.py b/zerver/worker/thumbnail.py index cedc57a160..7101258240 100644 --- a/zerver/worker/thumbnail.py +++ b/zerver/worker/thumbnail.py @@ -59,8 +59,9 @@ def ensure_thumbnails(image_attachment: ImageAttachment) -> int: return 0 written_images = 0 - image_bytes = BytesIO() - save_attachment_contents(image_attachment.path_id, image_bytes) + with BytesIO() as f: + save_attachment_contents(image_attachment.path_id, f) + image_bytes = f.getvalue() try: # TODO: We could save some computational time by using the same # bytes if multiple resolutions are larger than the source @@ -96,7 +97,7 @@ def ensure_thumbnails(image_attachment: ImageAttachment) -> int: else: load_opts = "n=1" resized = pyvips.Image.thumbnail_buffer( - image_bytes.getbuffer(), + image_bytes, thumbnail_format.max_width, height=thumbnail_format.max_height, option_string=load_opts,