X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;ds=sidebyside;f=plomtask%2Fprocesses.py;h=c4ccfa8fd3926491bf1a52fc3c2c36d6d271cd63;hb=10af8a54a17047a4554d4b8d051a238271c74906;hp=e67b13414e26d40a87e77545ce57d238bc050028;hpb=ee18435127ad396c24dbee2c7efcdbe6810d5a91;p=plomtask diff --git a/plomtask/processes.py b/plomtask/processes.py index e67b134..c4ccfa8 100644 --- a/plomtask/processes.py +++ b/plomtask/processes.py @@ -4,9 +4,10 @@ from dataclasses import dataclass from typing import Set, Any from sqlite3 import Row from plomtask.db import DatabaseConnection, BaseModel -from plomtask.misc import VersionedAttribute +from plomtask.versioned_attributes import VersionedAttribute from plomtask.conditions import Condition, ConditionsRelations -from plomtask.exceptions import NotFoundException, BadFormatException +from plomtask.exceptions import (NotFoundException, BadFormatException, + HandledException) @dataclass @@ -170,13 +171,23 @@ class Process(BaseModel[int], ConditionsRelations): step.save(db_conn) def remove(self, db_conn: DatabaseConnection) -> None: - """Remove from DB, with dependencies.""" + """Remove from DB, with dependencies. + + Guard against removal of Processes in use. + """ assert isinstance(self.id_, int) + for _ in db_conn.row_where('process_steps', 'step_process', self.id_): + raise HandledException('cannot remove Process in use') + for _ in db_conn.row_where('todos', 'process', self.id_): + raise HandledException('cannot remove Process in use') db_conn.delete_where('process_conditions', 'process', self.id_) db_conn.delete_where('process_enables', 'process', self.id_) db_conn.delete_where('process_disables', 'process', self.id_) for step in self.explicit_steps: step.remove(db_conn) + db_conn.delete_where('process_titles', 'parent', self.id_) + db_conn.delete_where('process_descriptions', 'parent', self.id_) + db_conn.delete_where('process_efforts', 'parent', self.id_) super().remove(db_conn)