From 8c19dcd41208b316368dd9072cb4a544af3b752c Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:11:44 -0800 Subject: [PATCH] Fix: close the uploaded logo image with a context manager when sanitizing --- src/paperless/serialisers.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/paperless/serialisers.py b/src/paperless/serialisers.py index 81ccdf7f7..64abd1c18 100644 --- a/src/paperless/serialisers.py +++ b/src/paperless/serialisers.py @@ -296,9 +296,8 @@ class ApplicationConfigurationSerializer( return super().update(instance, validated_data) def _sanitize_raster_image(self, file: UploadedFile) -> UploadedFile: - try: + with Image.open(file) as image: data = BytesIO() - image = Image.open(file) image.save(data, format=image.format) data.seek(0) @@ -310,8 +309,6 @@ class ApplicationConfigurationSerializer( size=data.getbuffer().nbytes, charset=getattr(file, "charset", None), ) - finally: - image.close() def validate_app_logo(self, file: UploadedFile): """