taskwarrior icon indicating copy to clipboard operation
taskwarrior copied to clipboard

Modification of task description by example on-add hook does not take effect

Open maertsen opened this issue 1 year ago • 1 comments

For an on-add hook I've developed myself, I don't see modifications to the description reflected in the db. I can reproduce this behaviour with the example on-add from https://taskwarrior.org/docs/hooks_guide/, which is the focus of this bug report. I modified the print statement to make it work with python 3.

  • What command(s) did you run?

The debug command from the example (with an additional +test to make deletion easier):

$ task rc.debug.hooks=2 add +test -- Fix tw-98765
Timer Config::load (/Users/mya/.config/task/taskrc) 0.000895 sec
No context set
Found hook script /Users/mya/.config/task/hooks/on-add-bug-link.py
Found hook script /Users/mya/.config/task/hooks/on-add.message-id.py
  MODIFICATION tags <-- add 'test'
  MODIFICATION description <-- 'Fix tw-98765'
Hook: Calling /Users/mya/.config/task/hooks/on-add-bug-link.py
Hook: input
  {"description":"Fix tw-98765","entry":"20240429T132014Z","modified":"20240429T132014Z","status":"pending","uuid":"ffae184e-a938-4112-8e75-582e2cf9b86f","tags":["test"]}
Hooks: args
  api:2
  args:task rc.debug.hooks=2 add +test -- Fix tw-98765
  command:add
  rc:/Users/mya/.config/task/taskrc
  data:/Users/mya/Library/Application Support/task
  version:3.0.2
Timer Hooks::execute (/Users/mya/.config/task/hooks/on-add-bug-link.py) 0.033543 sec
Hook: output
  {"description": "Fix https://github.com/GothenburgBitFactory/taskwarrior/issues/tw-98765", "entry": "20240429T132014Z", "modified": "20240429T132014Z", "status": "pending", "uuid": "ffae184e-a938-4112-8e75-582e2cf9b86f", "tags": ["test"]}
  Link added
Hook: Completed with status 0
 
Hook: Calling /Users/mya/.config/task/hooks/on-add.message-id.py
Hook: input
  {"description": "Fix https://github.com/GothenburgBitFactory/taskwarrior/issues/tw-98765", "entry": "20240429T132014Z", "modified": "20240429T132014Z", "status": "pending", "uuid": "ffae184e-a938-4112-8e75-582e2cf9b86f", "tags": ["test"]}
Hooks: args
  api:2
  args:task rc.debug.hooks=2 add +test -- Fix tw-98765
  command:add
  rc:/Users/mya/.config/task/taskrc
  data:/Users/mya/Library/Application Support/task
  version:3.0.2
Timer Hooks::execute (/Users/mya/.config/task/hooks/on-add.message-id.py) 0.029455 sec
Hook: output
  {"description": "Fix https://github.com/GothenburgBitFactory/taskwarrior/issues/tw-98765", "entry": "20240429T132014Z", "modified": "20240429T132014Z", "status": "pending", "uuid": "ffae184e-a938-4112-8e75-582e2cf9b86f", "tags": ["test"]}
Hook: Completed with status 0
 
Perf task 3.0.2 - 20240429T132014Z init:3971 load:0 gc:0 filter:0 commit:0 sort:0 render:0 hooks:63214 other:7677 total:74862

Created task 23.
Configuration override rc.debug.hooks=2
Link added
  • What did you expect to happen?

I expected the hook to modify the description and for this modification to be reflected in subsequent output of task.

  • What actually happened?

The hook modifies the description, this is not reflected in the database.

$ task 23

Name          Value                               
ID            23                                  
Description   Fix tw-98765
Status        Pending                             
Entered       2024-04-29 15:20:14 (1h)
Last modified 2024-04-29 15:20:14 (1h)            
Tags          test
Virtual tags  PENDING READY TAGGED UNBLOCKED      
UUID          ffae184e-a938-4112-8e75-582e2cf9b86f
Urgency       0.8                                 
[tag_test     x]

    tags    0.8 *    1 =    0.8
                         ------
                            0.8
  • Paste the output of the task diag command.
$ task diag

task 3.0.2
   Platform: Darwin

Compiler
    Version: Apple LLVM 15.0.0 (clang-1500.3.9.4)
       Caps: +stdc +stdc_hosted +LP64 +c8 +i32 +l64 +vp64 +time_t64
 Compliance: C++17

Build Features
      CMake: 3.29.2
    libuuid: libuuid + uuid_unparse_lower
 Build type: Release

Configuration
       File: /Users/mya/.config/task/taskrc (found), 1395 bytes, mode 100644
       Data: /Users/mya/Library/Application Support/task (found), dir, mode 40755
    Locking: Enabled
         GC: Enabled
    $EDITOR: vim
Hooks
     System: Enabled
   Location: /Users/mya/.config/task/hooks
     Active: on-add-bug-link.py   (executable)
             on-add.message-id.py (executable)
   Inactive: 

Tests
   Terminal: 115x77
       Dups: Scanned 40 tasks for duplicate UUIDs:
             No duplicates found
 Broken ref: Scanned 40 tasks for broken references:
             No broken references found

For reference, the modified hook:

#!/usr/bin/env python3

import sys
import re
import json

added_task = json.loads(sys.stdin.readline())
original = added_task['description']

added_task['description'] = re.sub(r'\b(tw-\d+)\b',
                                   r'https://github.com/GothenburgBitFactory/taskwarrior/issues/\1',
                                   original,
                                   flags=re.IGNORECASE)

print(json.dumps(added_task))

if original != added_task['description']:
    print('Link added')

sys.exit(0)

maertsen avatar Apr 29 '24 14:04 maertsen

I believe the included on-add.the hook could be used as a (failing) test-case, but I'm unsure how to hook it up to the testing framework, so I have refrained from opening a PR.

maertsen avatar Apr 29 '24 15:04 maertsen

Fixed in https://github.com/GothenburgBitFactory/taskwarrior/commit/fb16dbf7cf601a5c501b95cefcb0f74ee366f740

maertsen avatar May 15 '24 07:05 maertsen