From: Christian Heller Date: Mon, 29 Apr 2024 02:58:32 +0000 (+0200) Subject: Fix buggy Todo saving/removing. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/pick_tasks?a=commitdiff_plain;h=db1c88ab178f6ec54a994f2789c9db25604fcd83;p=plomtask Fix buggy Todo saving/removing. --- 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_)