Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin/task-processor): handle no task run #3196

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/task_processor/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from django.contrib import admin

from task_processor.models import RecurringTask
Expand All @@ -14,5 +16,7 @@ class RecurringTaskAdmin(admin.ModelAdmin):
)
readonly_fields = ("args", "kwargs")

def last_run_status(self, instance: RecurringTask) -> str:
return instance.task_runs.order_by("-started_at").first().result
def last_run_status(self, instance: RecurringTask) -> Optional[str]:
return getattr(
instance.task_runs.order_by("-started_at").first(), "result", None
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def last_run_status(self, instance: RecurringTask) -> Optional[str]:
return getattr(
instance.task_runs.order_by("-started_at").first(), "result", None
)
def last_run_status(self, instance: RecurringTask) -> Optional[str]:
if last_run := instance.task_runs.order_by("-started_at").first():
return last_run.result
return None

Slight preference for this aethetically but have approved regardless.