From d4c3b7614d75e70fce2f9c452e9a6fbb460fcbb5 Mon Sep 17 00:00:00 2001 From: Trenton Holmes Date: Tue, 9 Aug 2022 15:50:03 -0700 Subject: [PATCH] Catch all exceptions during the task creation so some error here, but not with a file, will allow consumption to run --- src/documents/signals/handlers.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index e2f4fb4f7..cf6bcc0ae 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -11,7 +11,6 @@ from django.contrib.contenttypes.models import ContentType from django.db import DatabaseError from django.db import models from django.db.models import Q -from django.db.utils import OperationalError from django.dispatch import receiver from django.utils import termcolors from django.utils import timezone @@ -514,7 +513,9 @@ def init_paperless_task(sender, task, **kwargs): paperless_task.name = task["name"] paperless_task.created = task["started"] paperless_task.save() - except OperationalError as e: + except Exception as e: + # Don't let an exception in the signal handlers prevent + # a document from being consumed. logger.error(f"Creating PaperlessTask failed: {e}") @@ -527,10 +528,10 @@ def paperless_task_started(sender, task, **kwargs): ) paperless_task.started = timezone.now() paperless_task.save() - except OperationalError as e: - logger.error(f"Creating PaperlessTask failed: {e}") except PaperlessTask.DoesNotExist: pass + except Exception as e: + logger.error(f"Creating PaperlessTask failed: {e}") @receiver(models.signals.post_save, sender=django_q.models.Task) @@ -542,7 +543,7 @@ def update_paperless_task(sender, instance, **kwargs): ) paperless_task.attempted_task = instance paperless_task.save() - except OperationalError as e: - logger.error(f"Creating PaperlessTask failed: {e}") except PaperlessTask.DoesNotExist: pass + except Exception as e: + logger.error(f"Creating PaperlessTask failed: {e}")