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

jrnl crashes when adding tag argument after --change-time #1644

Closed
richardjs opened this issue Nov 30, 2022 · 1 comment · Fixed by #1669
Closed

jrnl crashes when adding tag argument after --change-time #1644

richardjs opened this issue Nov 30, 2022 · 1 comment · Fixed by #1669
Labels
bug Something isn't working 📌 This can't go stale ready for pr Okay to start work. Feel free to ask questions.

Comments

@richardjs
Copy link
Contributor

Diagnostic output

jrnl: v3.3
Python: 3.10.8 (main, Nov 1 2022, 14:18:21) [GCC 12.2.0]
OS: Linux 5.15.80-1-lts

Current Behavior

The following command produces an exception:

$ jrnl -1 --edit --change-time @tag
┏━ Error ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃  TypeError                                                                  ┃
┃  '<' not supported between instances of 'datetime.datetime' and 'NoneType'  ┃
┃                                                                             ┃
┃  This is probably a bug. Please file an issue at:                           ┃
┃  https://github.com/jrnl-org/jrnl/issues/new/choose                         ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Expected Behavior

jrnl should open the most recent entry with @tag for editing, changing the time to the current time. That is to say, it should do the same as this command (which has the same arguments in a different order):

jrnl -1 @pomodoros --edit --change-time

Else, if that's complicated by looking for an optional argument to --change-time, it should produce a user-accessible error message.

Repro Steps

Running

jrnl -1 --edit --change-time @tag

(See "Current Behavior" above)

Debug output

$ jrnl -1 --edit --change-time @tag --debug
DEBUG    root         Parsed args: Namespace(debug=True, preconfig_cmd=None, postconfig_cmd=None, filename=None, on_date=None, today_in_history=False, month=None, day=None, year=None, start_date=None, end_date=None, contains=None, strict=False, starred=False, limit=1, excluded=[], edit=True, delete=False, change_time='@tag', export=False, tags=False, short=False, config_override=[], config_file_path='', text=[])
DEBUG    root         Reading configuration from file /home/redacted/.config/jrnl/jrnl.yaml
DEBUG    root         Using configuration "{'colors': {'body': 'none', 'date': 'none', 'tags': 'none', 'title': 'none'}, 'default_hour': 17, 'default_minute': 5, 'editor': 'emacs -nw', 'encrypt': False, 'highlight': True, 'indent_character': '|', 'journals': {'default': '/home/redacted/journal.txt', 'more_redacted_journals': 'redacted'}, 'linewrap': 200, 'tagsymbols': '@', 'template': False, 'timeformat': '%Y-%m-%d %H:%M', 'version': 'v2.7'}"
DEBUG    root         Using journal name: default
DEBUG    root         opened PlainJournal with 89 entries
  File "/usr/lib/python3.10/site-packages/jrnl/cli.py", line 39, in cli
    status_code = run(args)
  File "/usr/lib/python3.10/site-packages/jrnl/jrnl.py", line 72, in run
    search_mode(**kwargs)
  File "/usr/lib/python3.10/site-packages/jrnl/jrnl.py", line 191, in search_mode
    _change_time_search_results(no_prompt=no_change_time_prompt, **kwargs)
  File "/usr/lib/python3.10/site-packages/jrnl/jrnl.py", line 431, in _change_time_search_results
    journal.sort()
  File "/usr/lib/python3.10/site-packages/jrnl/Journal.py", line 194, in sort
    self.entries = sorted(self.entries, key=lambda entry: entry.date)
╭────────────────────────────── Traceback (most recent call last) ──────────────────────────────╮
│ /usr/lib/python3.10/site-packages/jrnl/cli.py:39 in cli                                       │
│                                                                                               │
│   38 │   │                                                                                    │
│ ❱ 39 │   │   status_code = run(args)                                                          │
│   40                                                                                          │
│                                                                                               │
│ /usr/lib/python3.10/site-packages/jrnl/jrnl.py:72 in run                                      │
│                                                                                               │
│    71 │   else:                                                                               │
│ ❱  72 │   │   search_mode(**kwargs)                                                           │
│    73                                                                                         │
│                                                                                               │
│ /usr/lib/python3.10/site-packages/jrnl/jrnl.py:191 in search_mode                             │
│                                                                                               │
│   190 │   │   │   no_change_time_prompt = len(journal.entries) == 1                           │
│ ❱ 191 │   │   │   _change_time_search_results(no_prompt=no_change_time_prompt, **kwargs)      │
│   192                                                                                         │
│                                                                                               │
│ /usr/lib/python3.10/site-packages/jrnl/jrnl.py:431 in _change_time_search_results             │
│                                                                                               │
│   430 │   │   journal.entries += other_entries                                                │
│ ❱ 431 │   │   journal.sort()                                                                  │
│   432 │   │   journal.write()                                                                 │
│                                                                                               │
│ /usr/lib/python3.10/site-packages/jrnl/Journal.py:194 in sort                                 │
│                                                                                               │
│   193 │   │   """Sorts the Journal's entries by date"""                                       │
│ ❱ 194 │   │   self.entries = sorted(self.entries, key=lambda entry: entry.date)               │
│   195                                                                                         │
╰───────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: '<' not supported between instances of 'datetime.datetime' and 'NoneType'
┏━ Error ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃  TypeError                                                                  ┃
┃  '<' not supported between instances of 'datetime.datetime' and 'NoneType'  ┃
┃                                                                             ┃
┃  This is probably a bug. Please file an issue at:                           ┃
┃  https://github.com/jrnl-org/jrnl/issues/new/choose                         ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Other Information

No response

@richardjs richardjs added 🆕 New! bug Something isn't working labels Nov 30, 2022
@micahellison micahellison changed the title Bug Report jrnl crashes when adding tag argument after --change-time Jan 7, 2023
@micahellison
Copy link
Member

Hi @richardjs, thanks for filing this. I was able to simplify the repro steps a bit -- it turns out this happens whenever a @tag is after --change-time, like so:

jrnl --change-time @tag

jrnl's argument parser is erroneously parsing the tag as a parameter of change-time.

It turns out this is a problem with any argument that has a default and is followed by a tag. For instance, --format defaults to jrnl but running this crashes:

jrnl --format @tag

The workaround is supplying a parameter for these args, like jrnl --change-time now @tag or jrnl --format jrnl @tag though we would love a resolution to this.

A resolution should probably involve changing argparse's argument prefix handling behavior to pay attention to the tagsymbols config value. (unless there is a need for a more special case approach). It should have:

  • A resolution to the bug
  • New passing tests for the --change-time and --format repro steps above

@micahellison micahellison added ready for pr Okay to start work. Feel free to ask questions. 📌 This can't go stale and removed 🆕 New! labels Jan 7, 2023
@wren wren changed the title jrnl crashes when adding tag argument after --change-time jrnl crashes when adding tag argument after --change-time Jan 7, 2023
@wren wren closed this as completed Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📌 This can't go stale ready for pr Okay to start work. Feel free to ask questions.
Projects
None yet
3 participants