GothenburgBitFactory / tasklib

A Python library for interacting with taskwarrior databases.
http://tasklib.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
148 stars 28 forks source link

Task save fails through an unconventional dependency add #64

Closed huntrar closed 5 years ago

huntrar commented 5 years ago

Although adding dependencies should be done using LazyUUIDTaskSet.add, I previously made an attempt through directly assigning a LazyUUIDTaskSet (produced by deserialize_depends or direct instantiation) which produced the following Traceback:

>>> tw = tasklib.TaskWarrior(task_dir)
>>> task1 = tw.tasks.all()[0]
>>> task2 = tw.tasks.all()[1]
>>> task1['depends'] = task1.deserialize_depends(task2['uuid'])
>>> task1.save()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
  File "/home/huntrar/.local/lib/python3.5/site-packages/tasklib/task.py", line 144, in _modified_fields
    if new_value != old_value:
  File "/home/huntrar/.local/lib/python3.5/site-packages/tasklib/lazy.py", line 112, in __ne__
    return not (self == other)
  File "/home/huntrar/.local/lib/python3.5/site-packages/tasklib/lazy.py", line 109, in __eq__
    return set(t['uuid'] for t in other) == self._uuids
TypeError: 'NoneType' object is not iterable

The issue is in the equality operator in LazyUUIDTaskSet. When you are comparing the new and old data when checking for modified fields, the equality operator is assuming the compared object is an iterable when in fact the dict.get() method is returning None on account of having no preeexisting dependencies.

Note this issue only exists when modifying the depends field of a previously saved task. If you are creating the task for the first time and perform this assignment and then save, there are no issues.