]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: Update filename correctly if the document is in the trash (#8066)
authorTrenton H <797416+stumpylog@users.noreply.github.com>
Mon, 28 Oct 2024 02:45:31 +0000 (19:45 -0700)
committerGitHub <noreply@github.com>
Mon, 28 Oct 2024 02:45:31 +0000 (02:45 +0000)
* Fixes an issue where the filename is not updated if the document is in the trash (but the file is moved)

src/documents/signals/handlers.py
src/documents/tests/test_file_handling.py

index 0bf20fd5c7665cb2d3fb682664b28dac8a7a210c..73aee29366edbcfcdadc01c198844dd161d0dc4d 100644 (file)
@@ -348,6 +348,8 @@ def cleanup_document_deletion(sender, instance, **kwargs):
                         f"While deleting document {instance!s}, the file "
                         f"{filename} could not be deleted: {e}",
                     )
+            elif filename and not os.path.isfile(filename):
+                logger.warn(f"Expected {filename} tp exist, but it did not")
 
         delete_empty_directories(
             os.path.dirname(instance.source_path),
@@ -461,7 +463,7 @@ def update_filename_and_move_files(
                 shutil.move(old_archive_path, instance.archive_path)
 
             # Don't save() here to prevent infinite recursion.
-            Document.objects.filter(pk=instance.pk).update(
+            Document.global_objects.filter(pk=instance.pk).update(
                 filename=instance.filename,
                 archive_filename=instance.archive_filename,
                 modified=timezone.now(),
index e942b4daa6eee9e522b23d62a8bf49b24d923a59..476068a5193e86b42eb7587614db188e695265ce 100644 (file)
@@ -150,7 +150,7 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
 
         with (
             mock.patch(
-                "documents.signals.handlers.Document.objects.filter",
+                "documents.signals.handlers.Document.global_objects.filter",
             ) as m,
             disable_auditlog(),
         ):
@@ -865,7 +865,9 @@ class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, Test
             archive_filename="0000001.pdf",
             archive_checksum="B",
         )
-        with mock.patch("documents.signals.handlers.Document.objects.filter") as m:
+        with mock.patch(
+            "documents.signals.handlers.Document.global_objects.filter",
+        ) as m:
             m.side_effect = DatabaseError()
             doc.save()