From 883199b57e7363df3f01f75ab375d6cb6b304d00 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Mon, 17 Jun 2024 16:40:04 -0400 Subject: [PATCH] fix: raise an exception if Radio Settings are not found --- program/services.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/program/services.py b/program/services.py index 1d01adbf..4b0413c3 100644 --- a/program/services.py +++ b/program/services.py @@ -24,7 +24,7 @@ from typing import Literal, TypedDict from dateutil.relativedelta import relativedelta from dateutil.rrule import rrule -from rest_framework.exceptions import ValidationError +from rest_framework.exceptions import NotFound, ValidationError from django.conf import settings from django.core.exceptions import ObjectDoesNotExist @@ -816,13 +816,16 @@ def make_timeslot_entry(*, timeslot: TimeSlot) -> TimeslotEntry: def make_virtual_timeslot_entry(*, gap_start: datetime, gap_end: datetime) -> VirtualTimeslotEntry: """returns a virtual timeslot entry to fill the gap in between `gap_start` and `gap_end`.""" - return { - "end": gap_end.strftime("%Y-%m-%dT%H:%M:%S %z"), - "is_virtual": True, - "show_id": RadioSettings.objects.first().fallback_show.id, - "show_name": RadioSettings.objects.first().fallback_default_pool, - "start": gap_start.strftime("%Y-%m-%dT%H:%M:%S %z"), - } + if radio_settings := RadioSettings.objects.first(): + return { + "end": gap_end.strftime("%Y-%m-%dT%H:%M:%S %z"), + "is_virtual": True, + "show_id": radio_settings.fallback_show.id, + "show_name": radio_settings.fallback_default_pool, + "start": gap_start.strftime("%Y-%m-%dT%H:%M:%S %z"), + } + else: + raise NotFound("Radio settings with fallbacks not found.") def get_timerange_timeslot_entries( -- GitLab