Modification of task description by example on-add hook does not take effect
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 diagcommand.
$ 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)
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.
Fixed in https://github.com/GothenburgBitFactory/taskwarrior/commit/fb16dbf7cf601a5c501b95cefcb0f74ee366f740