Commit 5d144d10 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix crash when completing a child item after a 'dep add'

When doing a 'dep add' command, the parent lookup dictionary was not kept up to
date. Therefore there was an edge in the dependengy graph that did not exist in
the parent dict. When the child item is completed, then its dependency ID is
looked up, but it doesn't exist, resulting in a crash.

By adding the _add_edge method, it should be easier to keep the edges of the
graph and the content of the dictionary in sync.
parent 6ee462b6
...@@ -99,12 +99,12 @@ class TodoList(TodoListBase): ...@@ -99,12 +99,12 @@ class TodoList(TodoListBase):
for dep in \ for dep in \
[dep for dep in self._todos if dep.has_tag('p', dep_id)]: [dep for dep in self._todos if dep.has_tag('p', dep_id)]:
self._depgraph.add_edge(hash(p_todo), hash(dep), dep_id) self._add_edge(p_todo, dep, dep_id)
for dep_id in p_todo.tag_values('p'): for dep_id in p_todo.tag_values('p'):
try: try:
parent = self._parentdict[dep_id] parent = self._parentdict[dep_id]
self._depgraph.add_edge(hash(parent), hash(p_todo), dep_id) self._add_edge(parent, p_todo, dep_id)
except KeyError: except KeyError:
pass pass
...@@ -145,6 +145,10 @@ class TodoList(TodoListBase): ...@@ -145,6 +145,10 @@ class TodoList(TodoListBase):
# todo item couldn't be found, ignore # todo item couldn't be found, ignore
pass pass
def _add_edge(self, p_from_todo, p_to_todo, p_dep_id):
self._parentdict[p_dep_id] = p_from_todo
self._depgraph.add_edge(hash(p_from_todo), hash(p_to_todo), p_dep_id)
@_needs_dependencies @_needs_dependencies
def add_dependency(self, p_from_todo, p_to_todo): def add_dependency(self, p_from_todo, p_to_todo):
""" Adds a dependency from task 1 to task 2. """ """ Adds a dependency from task 1 to task 2. """
...@@ -200,7 +204,7 @@ class TodoList(TodoListBase): ...@@ -200,7 +204,7 @@ class TodoList(TodoListBase):
p_from_todo.set_tag('id', dep_id) p_from_todo.set_tag('id', dep_id)
p_to_todo.add_tag('p', dep_id) p_to_todo.add_tag('p', dep_id)
self._depgraph.add_edge(hash(p_from_todo), hash(p_to_todo), dep_id) self._add_edge(p_from_todo, p_to_todo, dep_id)
append_projects_to_subtodo() append_projects_to_subtodo()
append_contexts_to_subtodo() append_contexts_to_subtodo()
self.dirty = True self.dirty = True
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment