|
1 | 1 | import datetime
|
2 | 2 | import os
|
| 3 | +import uuid |
3 | 4 | from functools import wraps
|
4 | 5 | from huey import (
|
5 | 6 | CancelExecution, Huey as huey_Huey,
|
@@ -403,19 +404,35 @@ def historical_task(signal_name, task_obj, exception_obj=None, /, *, huey=None):
|
403 | 404 | scheduled_at = huey.scheduled_at_from_task(task_obj)
|
404 | 405 | if scheduled_at:
|
405 | 406 | th.scheduled_at = scheduled_at
|
406 |
| - from sync.models import Media, Source |
407 |
| - if not th.verbose_name and task_obj.args: |
408 |
| - key = task_obj.args[0] |
409 |
| - for model in (Media, Source,): |
| 407 | + if not th.verbose_name: |
| 408 | + try: |
| 409 | + from django.core.exceptions import ValidationError |
| 410 | + from sync.models import Media, Source |
| 411 | + except: |
| 412 | + pass |
| 413 | + else: |
410 | 414 | try:
|
411 |
| - model_instance = model.objects.get(pk=key) |
412 |
| - except (model.DoesNotExist, ValueError,): |
413 |
| - pass |
| 415 | + key = task_obj.args[0] |
| 416 | + instance_uuid_str = str(key) |
| 417 | + instance_uuid = uuid.UUID(instance_uuid_str) |
| 418 | + except IndexError: |
| 419 | + key = None |
| 420 | + except RuntimeError: |
| 421 | + instance_uuid_str = None |
| 422 | + except ValueError: |
| 423 | + instance_uuid = None |
414 | 424 | else:
|
415 |
| - if hasattr(model_instance, 'key'): |
416 |
| - th.verbose_name = f'{th.name} with: {model_instance.key}' |
417 |
| - if hasattr(model_instance, 'name'): |
418 |
| - th.verbose_name += f' / {model_instance.name}' |
| 425 | + for model in (Source, Media,): |
| 426 | + try: |
| 427 | + model_instance = model.objects.get(pk=instance_uuid) |
| 428 | + except (model.DoesNotExist, ValidationError,): |
| 429 | + pass |
| 430 | + else: |
| 431 | + if hasattr(model_instance, 'key'): |
| 432 | + th.verbose_name = f'{th.name} with: {model_instance.key}' |
| 433 | + if hasattr(model_instance, 'name'): |
| 434 | + th.verbose_name += f' / {model_instance.name}' |
| 435 | + break |
419 | 436 | elif signal_name == signals.SIGNAL_SCHEDULED:
|
420 | 437 | scheduled_at = huey.scheduled_at_from_task(task_obj)
|
421 | 438 | if scheduled_at:
|
|
0 commit comments