GothenburgBitFactory / tasklib

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

Error accessing original values from a on-modify hook #125

Open lyndhurst opened 1 year ago

lyndhurst commented 1 year ago

Hi, I have taskwarrior 2.6.2, and tasklib 2.5.1-2 installed with pacman.

Calling original values from a on-modify hook throws an error. Below are the steps to reproduce the error using a 'minimal' config generated by taskwarrior, and no other hooks than on-modify-tests.

#!/usr/bin/python3

import sys
from tasklib.task import Task

modified_task = Task.from_input()

old_tags = modified_task.original["tags"]

print(modified_task.export_data())
sys.exit(0)

Output:

❯ task 4 modify -test
Modifying task 4 'Some task'.
Traceback (most recent call last):
  File "/home/user/.config/task/tests/hooks/on-modify-tests", line 13, in <module>
    old_tags = modified_task.original["tags"]
               ~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/lib/python3.11/site-packages/tasklib/task.py", line 32, in __getitem__
    return copy.deepcopy(self.viewed_dict.__getitem__(key))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'tags'

task 4 does have a test tag originally, the same happens with t.original['description'] anyway.

Thanks in advance for your help.