diff --git a/exercise_definition/lib/definition_manager.py b/exercise_definition/lib/definition_manager.py index bd21fe1c285d5b315aa3e47cd9caf2986f1222bc..d83ef50014f39256d5c8f399f812caa757162e60 100644 --- a/exercise_definition/lib/definition_manager.py +++ b/exercise_definition/lib/definition_manager.py @@ -2,6 +2,7 @@ import os from django.conf import settings +from common_lib.exceptions import ExerciseOperationException from common_lib.logger import logger from common_lib.utils import get_model from exercise.lib.exercise_manager import ExerciseManager @@ -12,7 +13,17 @@ class DefinitionManager: @staticmethod def delete_definition(definition_id: int): definition = get_model(Definition, id=definition_id) - for exercise in definition.exercises.all(): + exercises = definition.exercises.all() + running_exercise_ids = [ + exercise.id for exercise in exercises if exercise.running + ] + if len(running_exercise_ids) != 0: + raise ExerciseOperationException( + f"Cannot delete this definition because " + f"these running exercises depend on it {running_exercise_ids}" + ) + + for exercise in exercises: ExerciseManager.delete_exercise(exercise.id) for file_info in definition.files.all():