From c573fa61cbe7b8f6e4736a07e24ee95b9fa3c127 Mon Sep 17 00:00:00 2001 From: stumpylog <797416+stumpylog@users.noreply.github.com> Date: Thu, 23 Jul 2026 15:54:23 -0700 Subject: [PATCH] Fix: cover zstd-rejection path and correct importer's zstd-hint message Adds a command-level test exercising the real zstd-unavailable branch in document_exporter, makes document_importer only append the "zstd archives require Python 3.14+" hint when zstd is actually among the unreadable codecs, and adds the lzma counterpart to the stored-level-rejection test for symmetry. Co-Authored-By: Claude Sonnet 5 --- .../management/commands/document_importer.py | 9 ++-- .../tests/test_management_exporter.py | 41 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/documents/management/commands/document_importer.py b/src/documents/management/commands/document_importer.py index 071047379..62ad7f59b 100644 --- a/src/documents/management/commands/document_importer.py +++ b/src/documents/management/commands/document_importer.py @@ -459,11 +459,14 @@ class Command(CryptMixin, PaperlessCommand): if not compress_type_readable(info.compress_type) } if unsupported: - names = ", ".join(sorted(unreadable_method_names(unsupported))) - raise CommandError( + names = sorted(unreadable_method_names(unsupported)) + message = ( f"This archive uses compression this Python cannot " - f"read ({names}). zstd archives require Python 3.14+.", + f"read ({', '.join(names)})." ) + if "zstd" in names: + message += " zstd archives require Python 3.14+." + raise CommandError(message) zf.extractall(tmp_dir) self.source = Path(tmp_dir) self._run_import() diff --git a/src/documents/tests/test_management_exporter.py b/src/documents/tests/test_management_exporter.py index c298367b2..3020dc7d5 100644 --- a/src/documents/tests/test_management_exporter.py +++ b/src/documents/tests/test_management_exporter.py @@ -1143,6 +1143,47 @@ class TestExportImport( skip_checks=True, ) + def test_zip_compression_level_rejected_for_lzma(self) -> None: + """ + GIVEN: + - A request to export to a zip file with --zip-compression lzma + WHEN: + - --zip-compression-level is also passed + THEN: + - A CommandError is raised (lzma ignores level entirely) + """ + with self.assertRaises(CommandError): + call_command( + "document_exporter", + self.target, + "--zip", + "--zip-compression", + "lzma", + "--zip-compression-level", + "5", + skip_checks=True, + ) + + def test_zstd_unavailable_raises_friendly_error(self) -> None: + """ + GIVEN: + - A Python runtime without zstd support (< 3.14) + WHEN: + - --zip-compression zstd is requested + THEN: + - A CommandError naming the Python version requirement is raised + """ + with self.assertRaises(CommandError) as e: + call_command( + "document_exporter", + self.target, + "--zip", + "--zip-compression", + "zstd", + skip_checks=True, + ) + self.assertIn("3.14", str(e.exception)) + def test_zip_compression_flag_resolves_to_sink_constant(self) -> None: """ GIVEN: