GothenburgBitFactory / tasklib

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

Addition of task can create stale ID reference if GC has not been run #97

Closed gour closed 3 years ago

gour commented 3 years ago

Hello,

I'm trying to integrate Taskwarrior with Claws-mail client and for the purpose I've modified the mutt2task script as follows (my Python skills are very rusty):

#!/usr/bin/env python3

""" 
Creates a new task with the given message's filename as annotation attachment.
"""

import email
import sys

from tasklib import TaskWarrior, Task

def get_task_description(message):
    description = 'claws: "{}"'.format(message['subject'])
    return description 

def main():
    try:
        file_name = sys.argv[1]
        fp = open(file_name)
        message = email.message_from_file(fp)
        desc = get_task_description(message)
        tw = TaskWarrior(data_location='~/task', create=False)
        task = Task(tw, description=desc, tags=['inbox','email'])
        task.save()
        task.add_annotation(str(file_name))
    except Exception as e:
        print(e)
        sys.exit(2)

if __name__ == "__main__":
    main()

which I try to use as Claws-mail's User Action.

The problem is that the script does not work all the time, iow. sometimes when invoked as:

claws2task /home/gour/.claws-mail/newscache/news.gmane.io/gmane.mail.sylpheed.claws.general/76558

it produces the following output:

Unique identifiers 177 with description: claws: "Re: Action to integrate Claws with Taskwarrior" matches multiple tasks: ['']

and sometimes it simply works correctly and creates a task with appropriate annotatation - I plan to add custom .desktop file to be able to use xdg-open to open annotated link with claws-mail --select somemsg.

Do you have any idea why the script does not work reliably?

Sincerely, Gour

tbabej commented 3 years ago

This turns out to be a problem with how taskwiki obtains ID references to newly added tasks. In particular, the above script fails to add annotation if and only if one runs a task done or task delete command prior to running it.

This happens because the mechanism for enforcing recurrence causes the TW to run a next report, which triggers GC and possibly invalidates the ID reference.