From 905b28c1d758c661f5b7217cefb424c173e45882 Mon Sep 17 00:00:00 2001 From: Trenton Holmes Date: Sat, 1 Oct 2022 07:57:40 -0700 Subject: [PATCH] When a document is a duplicate, include the title of the existing document in the fail message --- src/documents/consumer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/documents/consumer.py b/src/documents/consumer.py index d1b01290a..30899a20c 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -111,14 +111,16 @@ class Consumer(LoggingMixin): def pre_check_duplicate(self): with open(self.path, "rb") as f: checksum = hashlib.md5(f.read()).hexdigest() - if Document.objects.filter( + existing_doc = Document.objects.filter( Q(checksum=checksum) | Q(archive_checksum=checksum), - ).exists(): + ) + if existing_doc.exists(): if settings.CONSUMER_DELETE_DUPLICATES: os.unlink(self.path) self._fail( MESSAGE_DOCUMENT_ALREADY_EXISTS, - f"Not consuming {self.filename}: It is a duplicate.", + f"Not consuming {self.filename}: It is a duplicate of" + f" {existing_doc.get().title}", ) def pre_check_directories(self):