From fe73506747dcd592e1de0edd0c12e9455468708d Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Tue, 5 Jul 2022 16:41:17 +0100 Subject: [PATCH] Move file.open call into set-file-metadata method If the file is already open this is the same as seek(0), so there are no unwanted side effects from this. --- wagtail/documents/models.py | 2 ++ wagtail/documents/views/multiple.py | 1 - wagtail/images/models.py | 2 ++ wagtail/images/views/multiple.py | 1 - 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wagtail/documents/models.py b/wagtail/documents/models.py index 961e996f6c..832d7b3622 100644 --- a/wagtail/documents/models.py +++ b/wagtail/documents/models.py @@ -135,6 +135,8 @@ class AbstractDocument(CollectionMember, index.Indexed, models.Model): return self.file_hash def _set_document_file_metadata(self): + self.file.open() + # Set new document file size self.file_size = self.file.size diff --git a/wagtail/documents/views/multiple.py b/wagtail/documents/views/multiple.py index c3fbff2a4e..11995a4038 100644 --- a/wagtail/documents/views/multiple.py +++ b/wagtail/documents/views/multiple.py @@ -118,7 +118,6 @@ class CreateFromUploadedDocumentView(BaseCreateFromUploadView): os.path.basename(self.upload.file.name), self.upload.file.file, save=False ) self.object.uploaded_by_user = self.request.user - self.object.file.open() self.object._set_document_file_metadata() form.save() diff --git a/wagtail/images/models.py b/wagtail/images/models.py index a494855c95..9bdf59ec1e 100644 --- a/wagtail/images/models.py +++ b/wagtail/images/models.py @@ -237,6 +237,8 @@ class AbstractImage(ImageFileMixin, CollectionMember, index.Indexed, models.Mode return self.file_hash def _set_image_file_metadata(self): + self.file.open() + # Set new image file size self.file_size = self.file.size diff --git a/wagtail/images/views/multiple.py b/wagtail/images/views/multiple.py index d9f3b7eef2..b2f03c0a41 100644 --- a/wagtail/images/views/multiple.py +++ b/wagtail/images/views/multiple.py @@ -160,7 +160,6 @@ class CreateFromUploadedImageView(BaseCreateFromUploadView): os.path.basename(self.upload.file.name), self.upload.file.file, save=False ) self.object.uploaded_by_user = self.request.user - self.object.file.open() self.object._set_image_file_metadata() form.save()