From 9c62e55fe96bfc2973b395d73a4b5fde867eff3f Mon Sep 17 00:00:00 2001 From: tcely Date: Tue, 29 Jul 2025 01:13:45 -0400 Subject: [PATCH 1/3] Rework `SIGNAL_ENQUEUED` exception handling --- tubesync/common/huey.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/tubesync/common/huey.py b/tubesync/common/huey.py index 56a0a4a3..863cee40 100644 --- a/tubesync/common/huey.py +++ b/tubesync/common/huey.py @@ -1,5 +1,6 @@ import datetime import os +import uuid from functools import wraps from huey import ( CancelExecution, Huey as huey_Huey, @@ -403,19 +404,35 @@ def historical_task(signal_name, task_obj, exception_obj=None, /, *, huey=None): scheduled_at = huey.scheduled_at_from_task(task_obj) if scheduled_at: th.scheduled_at = scheduled_at - from sync.models import Media, Source - if not th.verbose_name and task_obj.args: - key = task_obj.args[0] - for model in (Media, Source,): + try: + from django.core.exceptions import ValidationError + from sync.models import Media, Source + except: + pass + else: + if not th.verbose_name: try: - model_instance = model.objects.get(pk=key) - except (model.DoesNotExist, ValueError,): - pass + key = task_obj.args[0] + instance_uuid_str = str(key) + instance_uuid = uuid.UUID(instance_uuid_str) + except IndexError: + key = None + except RuntimeError: + instance_uuid_str = None + except ValueError: + instance_uuid = None else: - if hasattr(model_instance, 'key'): - th.verbose_name = f'{th.name} with: {model_instance.key}' - if hasattr(model_instance, 'name'): - th.verbose_name += f' / {model_instance.name}' + for model in (Source, Media,): + try: + model_instance = model.objects.get(pk=instance_uuid_str) + except (model.DoesNotExist, ValidationError,): + pass + else: + if hasattr(model_instance, 'key'): + th.verbose_name = f'{th.name} with: {model_instance.key}' + if hasattr(model_instance, 'name'): + th.verbose_name += f' / {model_instance.name}' + break elif signal_name == signals.SIGNAL_SCHEDULED: scheduled_at = huey.scheduled_at_from_task(task_obj) if scheduled_at: From e68d21b4572782bd3d906cae6a577351c315b0aa Mon Sep 17 00:00:00 2001 From: tcely Date: Tue, 29 Jul 2025 01:32:58 -0400 Subject: [PATCH 2/3] Use the UUID instance in the filter --- tubesync/common/huey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/common/huey.py b/tubesync/common/huey.py index 863cee40..1d86f748 100644 --- a/tubesync/common/huey.py +++ b/tubesync/common/huey.py @@ -424,7 +424,7 @@ def historical_task(signal_name, task_obj, exception_obj=None, /, *, huey=None): else: for model in (Source, Media,): try: - model_instance = model.objects.get(pk=instance_uuid_str) + model_instance = model.objects.get(pk=instance_uuid) except (model.DoesNotExist, ValidationError,): pass else: From 2910fe863802ff129ce42c412cad3569c9573dbd Mon Sep 17 00:00:00 2001 From: tcely Date: Tue, 29 Jul 2025 01:48:22 -0400 Subject: [PATCH 3/3] Check the if condition before importing anything --- tubesync/common/huey.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tubesync/common/huey.py b/tubesync/common/huey.py index 1d86f748..434a24cb 100644 --- a/tubesync/common/huey.py +++ b/tubesync/common/huey.py @@ -404,13 +404,13 @@ def historical_task(signal_name, task_obj, exception_obj=None, /, *, huey=None): scheduled_at = huey.scheduled_at_from_task(task_obj) if scheduled_at: th.scheduled_at = scheduled_at - try: - from django.core.exceptions import ValidationError - from sync.models import Media, Source - except: - pass - else: - if not th.verbose_name: + if not th.verbose_name: + try: + from django.core.exceptions import ValidationError + from sync.models import Media, Source + except: + pass + else: try: key = task_obj.args[0] instance_uuid_str = str(key)