From bf9251eebb2fc173a66b7fc667f75ddb398447d4 Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Mon, 22 Jul 2024 15:29:01 +0100 Subject: [PATCH] Fix array index out of bounds. --- helper/exercises.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/helper/exercises.py b/helper/exercises.py index c516e6a..81fa7a5 100644 --- a/helper/exercises.py +++ b/helper/exercises.py @@ -1259,15 +1259,16 @@ def replace_exercise_if_exists(all_exams, current_exercise, current_exam, seen_k for exam in all_exams: exam_dict = exam.to_dict() - exercise_dict = exam_dict.get("parts", [])[0] - if len(exercise_dict.get("exercises", [])) > 0: - if any( - exercise["prompt"] == current_exercise["prompt"] and - any(exercise["options"][0]["text"] == current_option["text"] for current_option in - current_exercise["options"]) - for exercise in exercise_dict.get("exercises", [])[0]["questions"] - ): - return replace_exercise_if_exists(all_exams, generate_single_mc_level_question(), current_exam, seen_keys) + if len(exam_dict.get("parts", [])) > 0: + exercise_dict = exam_dict.get("parts", [])[0] + if len(exercise_dict.get("exercises", [])) > 0: + if any( + exercise["prompt"] == current_exercise["prompt"] and + any(exercise["options"][0]["text"] == current_option["text"] for current_option in + current_exercise["options"]) + for exercise in exercise_dict.get("exercises", [])[0]["questions"] + ): + return replace_exercise_if_exists(all_exams, generate_single_mc_level_question(), current_exam, seen_keys) return current_exercise, seen_keys