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

'task undo' errors out #4

Closed
duckunix opened this issue May 31, 2022 · 19 comments
Closed

'task undo' errors out #4

duckunix opened this issue May 31, 2022 · 19 comments

Comments

@duckunix
Copy link

So, I screw up from time to time, and want to remove a task I have just added, so I use the task undo function, however, this does not work well with the hook for onenote:

$ task undo

The last modification was made 2022-05-30

             Prior Values  Current Values
description                test
entry                      2022-05-30
modified                   2022-05-30
project                    inbox
status                     pending
uuid                       d3375e56-a49f-41be-8332-af63f86fed32

The undo command is not reversible.  Are you sure you want to revert to the previous state? (yes/no) yes
Hook Error: Expected 1 JSON task(s), found 0, in hook script: on-modify-onenote-manage-notes-annotation.py

Everything else is working fine for me. I know I could just delete the task, but I sometimes do not want any record of the mistake.

Thanks!

@thehunmonkgroup
Copy link
Owner

Can't reproduce.

What version of TaskWarrior are you using?

@duckunix
Copy link
Author

duckunix commented Jun 2, 2022

I am on 2.6.2:

task version

task 2.6.2 built for Linux
Copyright (C) 2006 - 2021 T. Babej, P. Beckingham, F. Hernandez.

Taskwarrior may be copied only under the terms of the MIT license, which may be found in the Taskwarrior source kit.

Documentation for Taskwarrior can be found using 'man task', 'man taskrc', 'man task-color', 'man task-sync' or at https://taskwarrior.org

@thehunmonkgroup
Copy link
Owner

Should have asked this earlier, I'll need the Python version that's running the hook script. There can be multiple versions of Python installed, by default the hook script uses the path returned by the shebang line:

#!/usr/bin/env python

@duckunix
Copy link
Author

duckunix commented Jun 2, 2022

Yeah, my bad. I should have included that as well:

[don:~/.task/hooks] $ head on-add-onenote-manage-notes-annotation.py
#!/usr/bin/env python

import os
import sys
import time
import json

LOG_FILEPATH = "/tmp/onenote.log"
NOTES_ANNOTATION_DESCRIPTION = "[Notes]"
DEBUG = "ONENOTE_DEBUG" in os.environ
[don:~/.task/hooks] $ which python
/usr/bin/python
[don:~/.task/hooks] $ /usr/bin/python --version
Python 3.10.4

@thehunmonkgroup
Copy link
Owner

Apply this patch to the on-modify hook script:

--- a/manage_notes_annotation.py
+++ b/manage_notes_annotation.py
@@ -124,5 +124,7 @@ if __name__ == '__main__':
   except:
     exit_error()
 
+  with open('/tmp/onenote.log', 'w') as f:
+    f.write(json.dumps(modified_task))
   print(json.dumps(modified_task))
   sys.exit(0)

Then cat /tmp/onenote.log and give me the results.

@thehunmonkgroup
Copy link
Owner

Can't reproduce:

[root@taskwarrior.local:/var/local/git/vit] # python --version
Python 3.10.4
[root@taskwarrior.local:/var/local/git/vit] # task --version
2.6.2
[root@taskwarrior.local:/var/local/git/vit] # task add foo
Created task 6.
[root@taskwarrior.local:/var/local/git/vit] # task 6

Name          Value                               
ID            6                                   
Description   foo
Status        Pending                             
Entered       2022-06-02 17:14:01 (8s)
Last modified 2022-06-02 17:14:01 (8s)            
Virtual tags  LATEST PENDING READY UNBLOCKED
UUID          1a4499ef-e715-4057-aa68-65a687ea4b7f
Urgency          0

[root@taskwarrior.local:/var/local/git/vit] # onenote 6
Modifying task 6 'foo'.
Modified 1 task.
[root@taskwarrior.local:/var/local/git/vit] # task 6

Name          Value                                        
ID            6                                            
Description   foo
                2022-06-02 17:14:30 [Notes]
Status        Pending                                      
Entered       2022-06-02 17:14:01 (34s)
Last modified 2022-06-02 17:14:30 (5s)                     
Virtual tags  ANNOTATED LATEST PENDING READY UDA UNBLOCKED
UUID          1a4499ef-e715-4057-aa68-65a687ea4b7f         
Urgency        0.8
Notes         bar                                          

    annotations    0.8 *    1 =    0.8
                                ------
                                   0.8

Date                Modification                  
2022-06-02 17:14:30 Annotation of '[Notes]' added.
                    Notes set to 'bar'.           

@duckunix
Copy link
Author

duckunix commented Jun 3, 2022

No joy:

[don:~/.task/hooks] $ onenote 338
Modifying task 338 'test'.
Modified 1 task.
Project 'inbox' is 94% complete (10 of 172 tasks remaining).
[don:~/.task/hooks] 4s $ task 338

Name          Value
ID            338
Description   test
                2022-06-02 21:59:35 [Notes]
Status        Pending
Project       inbox
Entered       2022-06-02 21:57:39 (1min)
Last modified 2022-06-02 21:59:35 (3s)
Virtual tags  ANNOTATED LATEST PENDING PROJECT READY UDA UNBLOCKED
UUID          f7626f80-0fb4-4576-aac8-140da2fb7779
Urgency        1.8
Notes         note

    project          1 *    1 =      1
    annotations    0.8 *    1 =    0.8
                                ------
                                   1.8

[don:~/.task/hooks] $ task undo

The last modification was made 2022-06-02

                       Prior Values                          Current Values
description            test                                  test
entry                  2022-06-02                            2022-06-02
modified               2022-06-02                            2022-06-02
project                inbox                                 inbox
status                 pending                               pending
uuid                   f7626f80-0fb4-4576-aac8-140da2fb7779  f7626f80-0fb4-4576-aac8-140da2fb7779
annotation_1654225175                                        [Notes]
notes                                                        note

The undo command is not reversible.  Are you sure you want to revert to the previous state? (yes/no) yes
Modified task reverted.
[don:~/.task/hooks] $ task undo

The last modification was made 2022-06-02

             Prior Values  Current Values
description                test
entry                      2022-06-02
modified                   2022-06-02
project                    inbox
status                     pending
uuid                       f7626f80-0fb4-4576-aac8-140da2fb7779

The undo command is not reversible.  Are you sure you want to revert to the previous state? (yes/no) yes
Hook Error: Expected 1 JSON task(s), found 0, in hook script: on-modify-onenote-manage-notes-annotation.py
[don:~/.task/hooks] 2s 4 $ cat /tmp/onenote.log
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /tmp/onenote.log
       │ Size: 2 B
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ {}
───────┴──────────────────────────────────────────────────────────────────

Tried on fully up-to-date Arch and Ubuntu 20.04.4 box, with same results. And add your patch.

@thehunmonkgroup
Copy link
Owner

Still cannot reproduce:

[root@taskwarrior.local:~] # task --version
2.6.2
[root@taskwarrior.local:~] # python --version
Python 3.10.4
[root@taskwarrior.local:~] # task

ID Active Age    Description          Urg 
 1 2.7y   2.7y   foo one                 6
 2 2.7y   2.7y   bar two                 6
 3 2.7y   2.7y   bing three              6
 4          6mo  test                 1.86
                   2022-06-02 [Notes]     
 5         19h   foo                   0.8
                   2022-06-02 [Notes]
 6         19h   foo                   0.8
                   2022-06-02 [Notes]     

6 tasks
[root@taskwarrior.local:~] # onenote 6
Modifying task 6 'foo'.
Modified 1 task.
[root@taskwarrior.local:~] # task undo

The last modification was made 2022-06-03

                       Prior Values                          Current Values                      
annotation_1654215270  [Notes]                                                                   
description            foo                                   foo
entry                  2022-06-02                            2022-06-02                          
modified               2022-06-02                            2022-06-03                          
notes                  bar                                   barbaz                              
status                 pending                               pending
uuid                   1a4499ef-e715-4057-aa68-65a687ea4b7f  1a4499ef-e715-4057-aa68-65a687ea4b7f
annotation_1654283885                                        [Notes]                             

The undo command is not reversible.  Are you sure you want to revert to the previous state? (yes/no) yes
Modified task reverted.
[root@taskwarrior.local:~] # 

At this point I'm forced to conclude it's an issue in your environment, so I'm going to leave it to you and close this issue. If you do come across a specific fix, please feel free to reopen.

@duckunix
Copy link
Author

duckunix commented Jun 3, 2022

The issue is not undo a note, but undoing the task vs deleting the issue.

@thehunmonkgroup
Copy link
Owner

Not really sure what you mean, the note is a UDA on the task, it's part of the task data, so rolling that back is undoing an edit to the task.

@duckunix
Copy link
Author

duckunix commented Jun 4, 2022

Maybe it would be better to show you.

I can create an task, run onenote, undo the onenote note, but then when I try to undo again to remove the note, it errors. This error happens even if I do not add a note:

[don] which python
/usr/bin/python
[don] /usr/bin/python --version
Python 3.10.4
[don] task diag
TASKRC override: /tmp/task/taskrc

task 2.6.2
   Platform: Linux

Compiler
    Version: 11.2.0
       Caps: +stdc +stdc_hosted +LP64 +c8 +i32 +l64 +vp64 +time_t64
 Compliance: C++17

Build Features
      CMake: 3.22.3
    libuuid: libuuid + uuid_unparse_lower
  libgnutls: 3.7.3
 Build type:

Configuration
       File: /tmp/task/taskrc (found), 1433 bytes, mode 100660
       Data: /tmp/task (found), dir, mode 40770
     TASKRC: /tmp/task/taskrc
    Locking: Enabled
         GC: Enabled
    $EDITOR: vim
     Server:
         CA: -
Certificate: -
        Key: -
      Trust: strict
    Ciphers: NORMAL
      Creds:

Hooks
     System: Enabled
   Location: /tmp/task/hooks
     Active: on-add-onenote-manage-notes-annotation.py    (executable)
             on-add.blocks_attr.py                        (executable) (symlink)
             on-launch.blocks_attr.py                     (executable) (symlink)
             on-modify-onenote-manage-notes-annotation.py (executable)
             on-modify.blocks_attr.py                     (executable)
             on-modify.timewarrior                        (executable)
   Inactive: on-exit                                      (not executable)
             on-modify                                    (not executable)

Tests
   Terminal: 170x71
       Dups: Scanned 0 tasks for duplicate UUIDs:
             No duplicates found
 Broken ref: Scanned 0 tasks for broken references:
             No broken references found

[don] task add This is a test
TASKRC override: /tmp/task/taskrc
Created task 1.
[don] task
TASKRC override: /tmp/task/taskrc

ID Age  Description    Urg
 1 2s   This is a test    0

1 task
[don] onenote 1
[don] task 1
TASKRC override: /tmp/task/taskrc

Name          Value
ID            1
Description   This is a test
                2022-06-03 20:20:38 [Notes]
Status        Pending
Entered       2022-06-03 20:20:10 (51s)
Last modified 2022-06-03 20:20:39 (22s)
Virtual tags  ANNOTATED LATEST PENDING READY UDA UNBLOCKED
UUID          74efd7fe-9922-4165-b138-878714080185
Urgency        0.8
Notes         This is a test note

    annotations    0.8 *    1 =    0.8
                                ------
                                   0.8

Date                Modification
2022-06-03 20:20:39 Annotation of '[Notes]' added.
                    Notes set to 'This is a test note'.

[don] task undo

The last modification was made 2022-06-03

                       Prior Values                          Current Values
description            This is a test                        This is a test
entry                  2022-06-03                            2022-06-03
modified               2022-06-03                            2022-06-03
status                 pending                               pending
uuid                   74efd7fe-9922-4165-b138-878714080185  74efd7fe-9922-4165-b138-878714080185
annotation_1654305638                                        [Notes]
notes                                                        This is a test note

The undo command is not reversible.  Are you sure you want to revert to the previous state? (yes/no) yes
Modified task reverted.
TASKRC override: /tmp/task/taskrc
[don] task 1
TASKRC override: /tmp/task/taskrc

Name          Value
ID            1
Description   This is a test
Status        Pending
Entered       2022-06-03 20:20:10 (1min)
Last modified 2022-06-03 20:20:10 (1min)
Virtual tags  LATEST PENDING READY UNBLOCKED
UUID          74efd7fe-9922-4165-b138-878714080185
Urgency          0

[don] task undo

The last modification was made 2022-06-03

             Prior Values  Current Values
description                This is a test
entry                      2022-06-03
modified                   2022-06-03
status                     pending
uuid                       74efd7fe-9922-4165-b138-878714080185

The undo command is not reversible.  Are you sure you want to revert to the previous state? (yes/no) yes
TASKRC override: /tmp/task/taskrc
Hook Error: Expected 1 JSON task(s), found 0, in hook script: on-modify-onenote-manage-notes-annotation.py

Hope that explains it.

@thehunmonkgroup
Copy link
Owner

I was not able to reproduce this bug before because I was not clear on the use case, it never even occurred to me to remove a task by undoing it, so I was only checking the modify case. I've now been able to reproduce this bug.

@duckunix
Copy link
Author

duckunix commented Jun 5, 2022

Works now! Many thanks for putting up with me.

@thehunmonkgroup
Copy link
Owner

Good to hear. Curious, since you're using TaskWarrior 2.6.2, how are you working around #3 ?

@duckunix
Copy link
Author

duckunix commented Jun 6, 2022

Simple hack:

diff onenote ~/bin/onenote
9c9
< newline="\n"
---
> newline="\\n"
137c137,138
<       echo "${notes}" | sed "s/${newline}/\\$linefeed/g" | ONENOTE_TASK=${task_number} ${pipe_editor} | ${0} ${task_number} ${consume_arg}
---
>       #echo "${notes}" | sed "s/${newline}/\\$linefeed/g" | ONENOTE_TASK=${task_number} ${pipe_editor} | ${0} ${task_number} ${consume_arg}
>       echo "${notes}" | sed 's/\\n/\n/g' | ONENOTE_TASK=${task_number} ${pipe_editor} | ${0} ${task_number} ${consume_arg}

@thehunmonkgroup
Copy link
Owner

Yeah. I've been hesitant to put a fix into Onenote because I suspect any fix in TaskWarrior will re-break things. I'll see if I can move that TaskWarrior bug along...

@duckunix
Copy link
Author

duckunix commented Jun 6, 2022

Which is why I put it in my local copy and did not submit a PR. It is working for me, so I am good.

Thanks a again for this software and helping me fix my use case.

@thehunmonkgroup
Copy link
Owner

Would you be willing to post your patch to #3 so that others may find and benefit from it?

@duckunix
Copy link
Author

duckunix commented Jun 7, 2022

Would you be willing to post your patch to #3 so that others may find and benefit from it?

Done.

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

No branches or pull requests

2 participants