Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix: use float parsing for importer manifest records with a passphrase (#14483)

Trenton Ha8b835fcd023
diff --git a/src/documents/management/commands/document_importer.py b/src/documents/management/commands/document_importer.py
index e00244369..fa0e4bd33 100644
--- a/src/documents/management/commands/document_importer.py
+++ b/src/documents/management/commands/document_importer.py
@@ -66,7 +66,7 @@ def iter_manifest_records(path: Path) -> Generator[dict, None, None]:
"""Yield records one at a time from a manifest JSON array via ijson."""
try:
with path.open("rb") as f:
- yield from ijson.items(f, "item")
+ yield from ijson.items(f, "item", use_float=True)
except ijson.JSONError as e:
raise CommandError(f"Failed to parse manifest file {path}: {e}") from e
diff --git a/src/documents/tests/test_management_exporter.py b/src/documents/tests/test_management_exporter.py
index 3bfc909c8..b4cee95da 100644
--- a/src/documents/tests/test_management_exporter.py
+++ b/src/documents/tests/test_management_exporter.py
@@ -50,6 +50,7 @@ from documents.settings import EXPORTER_FILE_NAME
from documents.settings import EXPORTER_SHARE_LINK_BUNDLE_NAME
from documents.settings import EXPORTER_THUMBNAIL_NAME
from documents.tests.utils import SampleDirMixin
+from paperless.models import ApplicationConfiguration
from paperless_mail.models import MailAccount
from paperless_testing.assertions import FileSystemAssertsMixin
from paperless_testing.dirs import DirectoriesMixin
@@ -1402,6 +1403,45 @@ class TestCryptExportImport(
social_token = SocialToken.objects.first()
self.assertIsNotNone(social_token)
+ def test_import_passphrase_with_float_field(self) -> None:
+ """
+ GIVEN:
+ - An application configuration with a float field set
+ WHEN:
+ - Export and import are run with a passphrase
+ THEN:
+ - The import succeeds and the float value is preserved
+ """
+ ApplicationConfiguration.objects.update_or_create(
+ pk=1,
+ defaults={"rotate_pages_threshold": 12.5},
+ )
+
+ call_command(
+ "document_exporter",
+ "--no-progress-bar",
+ "--passphrase",
+ "securepassword",
+ self.target,
+ skip_checks=True,
+ )
+
+ ApplicationConfiguration.objects.all().delete()
+
+ call_command(
+ "document_importer",
+ "--no-progress-bar",
+ "--passphrase",
+ "securepassword",
+ self.target,
+ skip_checks=True,
+ )
+
+ self.assertEqual(
+ ApplicationConfiguration.objects.get().rotate_pages_threshold,
+ 12.5,
+ )
+
def test_import_crypt_no_passphrase(self) -> None:
"""
GIVEN: