From db1c88ab178f6ec54a994f2789c9db25604fcd83 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 29 Apr 2024 04:58:32 +0200 Subject: [PATCH] Fix buggy Todo saving/removing. --- plomtask/todos.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plomtask/todos.py b/plomtask/todos.py index 3bd3491..a874a6d 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -222,6 +222,8 @@ class Todo(BaseModel[int], ConditionsRelations): raise NotFoundException('Process of Todo without ID (not saved?)') self.save_core(db_conn) assert isinstance(self.id_, int) + db_conn.rewrite_relations('todo_children', 'child', self.id_, + [[p.id_] for p in self.parents]) db_conn.rewrite_relations('todo_children', 'parent', self.id_, [[c.id_] for c in self.children]) db_conn.rewrite_relations('todo_conditions', 'todo', self.id_, @@ -234,10 +236,14 @@ class Todo(BaseModel[int], ConditionsRelations): def remove(self, db_conn: DatabaseConnection) -> None: """Remove from DB, including relations.""" assert isinstance(self.id_, int) - for child in self.children: + children_to_remove = self.children[:] + parents_to_remove = self.parents[:] + for child in children_to_remove: self.remove_child(child) - for parent in self.parents: + for parent in parents_to_remove: parent.remove_child(self) + db_conn.delete_where('todo_children', 'parent', self.id_) + db_conn.delete_where('todo_children', 'child', self.id_) db_conn.delete_where('todo_conditions', 'todo', self.id_) db_conn.delete_where('todo_enables', 'todo', self.id_) db_conn.delete_where('todo_disables', 'todo', self.id_) -- 2.30.2