From b6de46379dda4efa4bebc2391d5625f54f6b0f68 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 26 Oct 2024 22:29:32 -0700 Subject: [PATCH] Bulk edit too --- src/documents/bulk_edit.py | 17 ++++++++++++----- src/documents/tests/test_bulk_edit.py | 9 +++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/documents/bulk_edit.py b/src/documents/bulk_edit.py index 1aba8f9ec..2e3e5f591 100644 --- a/src/documents/bulk_edit.py +++ b/src/documents/bulk_edit.py @@ -159,13 +159,20 @@ def modify_custom_fields(doc_ids: list[int], add_custom_fields, remove_custom_fi @shared_task def delete(doc_ids: list[int]): - Document.objects.filter(id__in=doc_ids).delete() + try: + Document.objects.filter(id__in=doc_ids).delete() - from documents import index + from documents import index - with index.open_index_writer() as writer: - for id in doc_ids: - index.remove_document_by_id(writer, id) + with index.open_index_writer() as writer: + for id in doc_ids: + index.remove_document_by_id(writer, id) + except Exception as e: + if "Data too long for column" in str(e): + logger.warning( + "Detected a possible incompatible database column. See https://docs.paperless-ngx.com/troubleshooting/#convert-uuid-field", + ) + logger.error(f"Error deleting documents: {e!s}") return "OK" diff --git a/src/documents/tests/test_bulk_edit.py b/src/documents/tests/test_bulk_edit.py index d80116a80..c6e846a77 100644 --- a/src/documents/tests/test_bulk_edit.py +++ b/src/documents/tests/test_bulk_edit.py @@ -327,6 +327,15 @@ class TestBulkEdit(DirectoriesMixin, TestCase): ) self.assertEqual(groups_with_perms.count(), 2) + @mock.patch("documents.models.Document.delete") + def test_delete_documents_old_uuid_field(self, m): + m.side_effect = Exception("Data too long for column 'transaction_id' at row 1") + doc_ids = [self.doc1.id, self.doc2.id, self.doc3.id] + bulk_edit.delete(doc_ids) + with self.assertLogs(level="WARNING") as cm: + bulk_edit.delete(doc_ids) + self.assertIn("possible incompatible database column", cm.output[0]) + class TestPDFActions(DirectoriesMixin, TestCase): def setUp(self):