From 2bc5c28777c300ec1f0deee246126274b68f33e5 Mon Sep 17 00:00:00 2001 From: Matias Bordese Date: Tue, 1 Aug 2023 16:27:44 -0300 Subject: [PATCH] Skip past due swap requests when calculating events (#2718) --- CHANGELOG.md | 4 ++++ engine/apps/schedules/models/on_call_schedule.py | 3 +++ engine/apps/schedules/tests/test_on_call_schedule.py | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0bf94ae84..59d6c8e008 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Skip past due swap requests when calculating events ([2718](https://github.com/grafana/oncall/pull/2718)) + ### Fixed - Fix schedule final_events datetime filtering when splitting override ([#2715](https://github.com/grafana/oncall/pull/2715)) diff --git a/engine/apps/schedules/models/on_call_schedule.py b/engine/apps/schedules/models/on_call_schedule.py index a4fc4ccc03..7a70a8e429 100644 --- a/engine/apps/schedules/models/on_call_schedule.py +++ b/engine/apps/schedules/models/on_call_schedule.py @@ -649,6 +649,9 @@ def _insert_event(index: int, event: ScheduleEvent) -> int: # apply swaps sequentially for swap in swaps: + if swap.is_past_due: + # ignore untaken expired requests + continue i = 0 while i < len(events): event = events.pop(i) diff --git a/engine/apps/schedules/tests/test_on_call_schedule.py b/engine/apps/schedules/tests/test_on_call_schedule.py index 27af60a90c..744fbea352 100644 --- a/engine/apps/schedules/tests/test_on_call_schedule.py +++ b/engine/apps/schedules/tests/test_on_call_schedule.py @@ -2329,11 +2329,16 @@ def test_swap_request_no_changes( # setup swap requests tomorrow = today + timezone.timedelta(days=1) + # user not in schedule make_shift_swap_request(schedule, other_user, swap_start=today, swap_end=tomorrow) + # deleted request make_shift_swap_request(schedule, user, swap_start=today, swap_end=tomorrow, deleted_at=today) + # swap request in the past make_shift_swap_request( schedule, user, swap_start=today - timezone.timedelta(days=7), swap_end=tomorrow - timezone.timedelta(days=7) ) + # untaken swap in progress (past due) + make_shift_swap_request(schedule, user, swap_start=today - timezone.timedelta(days=1), swap_end=tomorrow) events_after = schedule.filter_events(today, today + timezone.timedelta(days=2)) assert events_before == events_after