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: