From 9a28e2893a3ad221cc164afdd6e4530e7731d5c3 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Fri, 10 Apr 2026 14:00:47 -0700 Subject: [PATCH] Encodes the string just once for compare json --- .../management/commands/document_exporter.py | 26 +++++++------------ .../tests/test_management_exporter.py | 2 -- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/documents/management/commands/document_exporter.py b/src/documents/management/commands/document_exporter.py index 336ab7977..a719cc89e 100644 --- a/src/documents/management/commands/document_exporter.py +++ b/src/documents/management/commands/document_exporter.py @@ -373,7 +373,7 @@ class Command(CryptMixin, PaperlessCommand): self.dump() - if self.zip_export and self.zip_file is not None: + if self.zip_file is not None: self.zip_file.close() self.zip_file = None self.zip_tmp_path.rename(self.zip_path) @@ -792,31 +792,23 @@ class Command(CryptMixin, PaperlessCommand): return target = target.resolve() + json_str = json.dumps( + content, + cls=DjangoJSONEncoder, + indent=2, + ensure_ascii=False, + ) perform_write = True if target in self.files_in_export_dir: self.files_in_export_dir.remove(target) if self.compare_json: target_checksum = hashlib.blake2b(target.read_bytes()).hexdigest() - src_str = json.dumps( - content, - cls=DjangoJSONEncoder, - indent=2, - ensure_ascii=False, - ) - src_checksum = hashlib.blake2b(src_str.encode("utf-8")).hexdigest() + src_checksum = hashlib.blake2b(json_str.encode("utf-8")).hexdigest() if src_checksum == target_checksum: perform_write = False if perform_write: - target.write_text( - json.dumps( - content, - cls=DjangoJSONEncoder, - indent=2, - ensure_ascii=False, - ), - encoding="utf-8", - ) + target.write_text(json_str, encoding="utf-8") def check_and_copy( self, diff --git a/src/documents/tests/test_management_exporter.py b/src/documents/tests/test_management_exporter.py index 315353b04..7d2549bf1 100644 --- a/src/documents/tests/test_management_exporter.py +++ b/src/documents/tests/test_management_exporter.py @@ -703,8 +703,6 @@ class TestExportImport( - No files are written under SCRATCH_DIR during the export (the old workaround used a temp dir there) """ - from django.conf import settings - shutil.rmtree(Path(self.dirs.media_dir) / "documents") shutil.copytree( Path(__file__).parent / "samples" / "documents",