Skip to content

Commit

Permalink
[round_robin] Do not crash on invalid duty start dates (#2301)
Browse files Browse the repository at this point in the history
  • Loading branch information
suhaibmujahid authored Dec 15, 2023
1 parent ede0a9f commit 00860cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 7 additions & 2 deletions bugbot/round_robin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion bugbot/round_robin_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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", {})
)
Expand Down

0 comments on commit 00860cf

Please sign in to comment.