From a3f34cb58019323e500a2de330e0e1a447888a27 Mon Sep 17 00:00:00 2001 From: Mikael Lenander Date: Sat, 23 Sep 2023 16:40:41 +0300 Subject: [PATCH] Fix ModuleRevealState crashing if it contains no exercises --- exercise/reveal_states.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exercise/reveal_states.py b/exercise/reveal_states.py index 5b41dc9df..eeee5e0a5 100644 --- a/exercise/reveal_states.py +++ b/exercise/reveal_states.py @@ -148,6 +148,8 @@ def __init__(self, module: Union[CourseModule, ModulePoints], student: Optional[ self.max_deviation: Optional[DeadlineRuleDeviation] = None def get_deadline(self) -> Optional[datetime.datetime]: + if len(self.exercises) == 0: + return None return max(_get_exercise_deadline(exercise) for exercise in self.exercises) def get_latest_deadline(self) -> Optional[datetime.datetime]: @@ -167,6 +169,8 @@ def get_latest_deadline(self) -> Optional[datetime.datetime]: deadlines.append( self.max_deviation.get_new_deadline(exercise_dict[self.max_deviation.exercise_id].closing_time) ) + if len(deadlines) == 0: + return None return max(deadlines) def get_points(self) -> Optional[int]: