Skip to content

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

Fix: disable custom field signals during import in 2.13.0 (#8065)

shamoon0d96cd03d5e7
diff --git a/src/documents/management/commands/document_importer.py b/src/documents/management/commands/document_importer.py
index 08812e9d0..22c626eba 100644
--- a/src/documents/management/commands/document_importer.py
+++ b/src/documents/management/commands/document_importer.py
@@ -34,6 +34,7 @@ from documents.settings import EXPORTER_ARCHIVE_NAME
from documents.settings import EXPORTER_CRYPTO_SETTINGS_NAME
from documents.settings import EXPORTER_FILE_NAME
from documents.settings import EXPORTER_THUMBNAIL_NAME
+from documents.signals.handlers import update_cf_instance_documents
from documents.signals.handlers import update_filename_and_move_files
from documents.utils import copy_file_with_basic_stats
from paperless import version
@@ -242,6 +243,7 @@ class Command(CryptMixin, BaseCommand):
self.decrypt_secret_fields()
+ # see /src/documents/signals/handlers.py
with (
disable_signal(
post_save,
@@ -253,6 +255,16 @@ class Command(CryptMixin, BaseCommand):
receiver=update_filename_and_move_files,
sender=Document.tags.through,
),
+ disable_signal(
+ post_save,
+ receiver=update_filename_and_move_files,
+ sender=CustomFieldInstance,
+ ),
+ disable_signal(
+ post_save,
+ receiver=update_cf_instance_documents,
+ sender=CustomField,
+ ),
):
if settings.AUDIT_LOG_ENABLED:
auditlog.unregister(Document)
diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py
index eec6b135e..0bf20fd5c 100644
--- a/src/documents/signals/handlers.py
+++ b/src/documents/signals/handlers.py
@@ -365,6 +365,7 @@ class CannotMoveFilesException(Exception):
pass
+# should be disabled in /src/documents/management/commands/document_importer.py handle
@receiver(models.signals.post_save, sender=CustomField)
def update_cf_instance_documents(sender, instance: CustomField, **kwargs):
"""
@@ -379,6 +380,7 @@ def update_cf_instance_documents(sender, instance: CustomField, **kwargs):
update_filename_and_move_files(sender, cf_instance)
+# should be disabled in /src/documents/management/commands/document_importer.py handle
@receiver(models.signals.post_save, sender=CustomFieldInstance)
@receiver(models.signals.m2m_changed, sender=Document.tags.through)
@receiver(models.signals.post_save, sender=Document)