From 00860cf6f13f1a089034b922c0d069d64b093b45 Mon Sep 17 00:00:00 2001 From: Suhaib Mujahid Date: Fri, 15 Dec 2023 07:45:18 -0500 Subject: [PATCH] [round_robin] Do not crash on invalid duty start dates (#2301) --- bugbot/round_robin.py | 9 +++++++-- bugbot/round_robin_calendar.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bugbot/round_robin.py b/bugbot/round_robin.py index f6e562468..a639e9712 100644 --- a/bugbot/round_robin.py +++ b/bugbot/round_robin.py @@ -12,7 +12,12 @@ from bugbot import logger, utils from bugbot.components import Components from bugbot.people import People -from bugbot.round_robin_calendar import BadFallback, Calendar, InvalidCalendar +from bugbot.round_robin_calendar import ( + BadFallback, + Calendar, + InvalidCalendar, + InvalidDateError, +) class RoundRobin(object): @@ -77,7 +82,7 @@ def feed(self, teams: Set[str] | None = None) -> None: self.data[component_name] = calendar - except (BadFallback, InvalidCalendar) as err: + except (BadFallback, InvalidCalendar, InvalidDateError) as err: logger.error(err) # If one the team's calendars failed, it is better to fail loud, # and disable all team's calendars. diff --git a/bugbot/round_robin_calendar.py b/bugbot/round_robin_calendar.py index 9f5acefd0..ad6956573 100644 --- a/bugbot/round_robin_calendar.py +++ b/bugbot/round_robin_calendar.py @@ -10,6 +10,7 @@ import recurring_ical_events import requests +from dateutil.parser import ParserError from dateutil.relativedelta import relativedelta from icalendar import Calendar as iCalendar from libmozdata import utils as lmdutils @@ -26,6 +27,10 @@ class BadFallback(Exception): pass +class InvalidDateError(ParserError): + """Raised when a date in a rotation calendar is invalid""" + + class Calendar: def __init__(self, fallback, team_name, people=None): self.people = People.get_instance() if people is None else people @@ -108,7 +113,12 @@ def __init__(self, cal, fallback, team_name, people=None): super().__init__(fallback, team_name, people=people) start_dates = cal.get("duty-start-dates", {}) if start_dates: - dates = sorted((lmdutils.get_date_ymd(d), d) for d in start_dates.keys()) + try: + dates = sorted((lmdutils.get_date_ymd(d), d) for d in start_dates) + except ParserError as err: + raise InvalidDateError( + f"Invalid duty start date for the {team_name} team: {err}" + ) from err self.set_team( list(start_dates[d] for _, d in dates), cal.get("triagers", {}) )