diff --git a/app/grandchallenge/cases/models.py b/app/grandchallenge/cases/models.py index 76bc7722a..05ecd9a58 100644 --- a/app/grandchallenge/cases/models.py +++ b/app/grandchallenge/cases/models.py @@ -134,7 +134,7 @@ def default_error_message(self): f"{n_errors} file{pluralize(n_errors)} could not be imported" ) - def get_error_handler(self, linked_object=None): + def get_error_handler(self, *, linked_object=None): from grandchallenge.algorithms.models import Job if linked_object: diff --git a/app/grandchallenge/cases/tasks.py b/app/grandchallenge/cases/tasks.py index b6f824976..8c4e1646a 100644 --- a/app/grandchallenge/cases/tasks.py +++ b/app/grandchallenge/cases/tasks.py @@ -140,6 +140,8 @@ def build_images( # noqa:C901 ) if linked_interface_slug: ci = ComponentInterface.objects.get(slug=linked_interface_slug) + else: + ci = None if linked_object_pk: try: @@ -178,18 +180,18 @@ def build_images( # noqa:C901 except DuplicateFilesException as e: _delete_session_files(upload_session=upload_session) error_handler.handle_error( - interface=ci if linked_interface_slug else None, + interface=ci, error_message=str(e), ) except (SoftTimeLimitExceeded, TimeLimitExceeded): error_handler.handle_error( - interface=ci if linked_interface_slug else None, + interface=ci, error_message="Time limit exceeded", ) except Exception: _delete_session_files(upload_session=upload_session) error_handler.handle_error( - interface=ci if linked_interface_slug else None, + interface=ci, error_message="An unexpected error occurred", ) logger.error("An unexpected error occurred", exc_info=True) diff --git a/app/grandchallenge/components/models.py b/app/grandchallenge/components/models.py index 210eabcab..5976d1c52 100644 --- a/app/grandchallenge/components/models.py +++ b/app/grandchallenge/components/models.py @@ -2435,7 +2435,7 @@ def get_current_value_for_interface(self, *, interface, user): ) raise e - def get_error_handler(self, linked_object=None): + def get_error_handler(self, *, linked_object=None): # local imports to prevent circular dependency from grandchallenge.algorithms.models import Job diff --git a/app/grandchallenge/core/error_handlers.py b/app/grandchallenge/core/error_handlers.py index a8b79c8c4..5d2b24fe9 100644 --- a/app/grandchallenge/core/error_handlers.py +++ b/app/grandchallenge/core/error_handlers.py @@ -91,7 +91,7 @@ def handle_error(self, *, error_message, user, interface): class SystemCIVErrorHandler(ErrorHandler): def handle_error(self, *, error_message, user, interface): Notification.send( - kind=NotificationType.NotificationTypeChoices.SYSTEM, + kind=NotificationType.NotificationTypeChoices.CIV_VALIDATION, message=f"Validation for interface {interface.title} failed.", description=f"Validation for interface {interface.title} failed: {error_message}", actor=user, diff --git a/app/grandchallenge/notifications/migrations/0004_alter_notification_type.py b/app/grandchallenge/notifications/migrations/0004_alter_notification_type.py index 296a7705e..c802be5a5 100644 --- a/app/grandchallenge/notifications/migrations/0004_alter_notification_type.py +++ b/app/grandchallenge/notifications/migrations/0004_alter_notification_type.py @@ -26,7 +26,10 @@ class Migration(migrations.Migration): ("JOB-STATUS", "Job status update"), ("IMAGE-IMPORT", "Image import status update"), ("FILE-COPY", "Validation failed while copying file"), - ("SYSTEM", "An unexpected error occurred"), + ( + "CIV-VALIDATION", + "Component Interface Value validation failed", + ), ], default="GENERIC", help_text="Of what type is this notification?", diff --git a/app/grandchallenge/notifications/models.py b/app/grandchallenge/notifications/models.py index 802554795..939a183fb 100644 --- a/app/grandchallenge/notifications/models.py +++ b/app/grandchallenge/notifications/models.py @@ -39,7 +39,9 @@ class NotificationTypeChoices(models.TextChoices): JOB_STATUS = "JOB-STATUS", _("Job status update") IMAGE_IMPORT_STATUS = "IMAGE-IMPORT", _("Image import status update") FILE_COPY_STATUS = "FILE-COPY", _("Validation failed while copying file") - SYSTEM = "SYSTEM", ("An unexpected error occurred") + CIV_VALIDATION = "CIV-VALIDATION", ( + "Component Interface Value validation failed" + ) class NotificationType: @@ -229,7 +231,7 @@ def get_receivers(*, kind, actor, action_object, target): # noqa: C901 return followers(action_object) elif kind in [ NotificationType.NotificationTypeChoices.FILE_COPY_STATUS, - NotificationType.NotificationTypeChoices.SYSTEM, + NotificationType.NotificationTypeChoices.CIV_VALIDATION, ]: return {actor} else: @@ -466,7 +468,7 @@ def print_notification(self, user): # noqa: C901 ) elif self.type in [ NotificationType.NotificationTypeChoices.FILE_COPY_STATUS, - NotificationType.NotificationTypeChoices.SYSTEM, + NotificationType.NotificationTypeChoices.CIV_VALIDATION, ]: return self.description