Skip to content
Snippets Groups Projects
Commit b01c9bf7 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

fix(program-generation): fix undefined behaviour around start and end query parameters

The radio program is a continuous stream of program slots. Clients can
expect that the program generated for their queries fit the start and
end parameters given by the client. However, they *cannot* expect the
actual radio program (in the form of Timeslot objects) to fit these
artifical boundaries.

As the program endpoint should always output the actual program
broadcasted by the radio we must include timeslots that
  * have started before the specified start query but end after it
  * or end after the specified end query but start before it.

The changes in this commit ensure that the program matches the given
range exactly and that planned timeslots in that range are always
included.
parent 3c82c6f6
No related branches found
No related tags found
1 merge request!54fix(program-generation): fix undefined behaviour around start and end query parameters
Pipeline #8345 failed
...@@ -720,13 +720,23 @@ def generate_program_entries( ...@@ -720,13 +720,23 @@ def generate_program_entries(
) )
def create_timeslot_entry(timeslot: TimeSlot): def create_timeslot_entry(timeslot: TimeSlot):
return create_entry(timeslot.start, timeslot.end, timeslot.schedule.show, timeslot) return create_entry(
# Ensure the program entry never starts before the requested start
# and never ends after the requested end.
max(timeslot.start, start),
min(timeslot.end, end),
timeslot.schedule.show,
timeslot,
)
if start is None: if start is None:
start = timezone.now() start = timezone.now()
if end is None: if end is None:
end = start + timedelta(days=1) end = start + timedelta(days=1)
queryset = queryset.filter(start__gte=start, start__lt=end) # Find all timeslots that
# * have started before the specified start value but end after it
# * or end after the specified end value but start before it
queryset = queryset.filter(end__gt=start, start__lt=end).order_by("start")
if not include_virtual: if not include_virtual:
yield from (create_timeslot_entry(timeslot) for timeslot in queryset) yield from (create_timeslot_entry(timeslot) for timeslot in queryset)
...@@ -744,5 +754,5 @@ def generate_program_entries( ...@@ -744,5 +754,5 @@ def generate_program_entries(
yield create_entry(entry_start, timeslot.start, fallback_show) yield create_entry(entry_start, timeslot.start, fallback_show)
yield create_timeslot_entry(timeslot) yield create_timeslot_entry(timeslot)
entry_start = timeslot.end entry_start = timeslot.end
if entry_start != end: if entry_start < end:
yield create_entry(entry_start, end, fallback_show) yield create_entry(entry_start, end, fallback_show)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment