Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gour opened this issue Sep 10, 2021 · 1 comment · Fixed by #101
Closed

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

gour opened this issue Sep 10, 2021 · 1 comment · Fixed by #101

Comments

@gour
Copy link

gour commented Sep 10, 2021

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 tbabej changed the title annotation is not (always) added Addition of task can create stale ID reference if GC has not been run Sep 13, 2021
@tbabej
Copy link
Sponsor Member

tbabej commented Sep 13, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants