From 0d96cd03d5e768f5bea579cf2c7d2d177fcaf65e Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 27 Oct 2024 18:43:24 -0700 Subject: [PATCH] Fix: disable custom field signals during import in 2.13.0 (#8065) --- .../management/commands/document_importer.py | 12 ++++++++++++ src/documents/signals/handlers.py | 2 ++ 2 files changed, 14 insertions(+) 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)