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

Wrong delete count when manually changing entries #1198

Closed
tiagoboldt opened this issue Feb 22, 2021 · 3 comments · Fixed by #1366
Closed

Wrong delete count when manually changing entries #1198

tiagoboldt opened this issue Feb 22, 2021 · 3 comments · Fixed by #1366
Labels
bug Something isn't working 📌 This can't go stale

Comments

@tiagoboldt
Copy link

tiagoboldt commented Feb 22, 2021

Environment

> jrnl --diagnostic
jrnl: v2.7
Python: 3.9.2 (default, Feb 19 2021, 17:43:04)
[Clang 12.0.0 (clang-1200.0.32.29)]
OS: Darwin 20.3.0
  • Install method: homebrew

Current Behavior

When editing a list of entries in my editor, and adding one entry in the list, after saving the file, the summary says that a negative number of entries was deleted.

> jrnl -n 5 --edit
[-1 entries deleted, 1 entry modified]

Expected Behavior

I would expect to see the following output when adding one entry and changing another:

> jrnl -n 5 --edit
[1 entry added, 0 entries deleted, 1 entry modified]

Repro Steps

Open a list of recent entries in your editor with the command above and add an additional entry between those.

@tiagoboldt tiagoboldt added 🆕 New! bug Something isn't working labels Feb 22, 2021
@wren wren added 📌 This can't go stale and removed 🆕 New! labels Feb 27, 2021
@micahellison
Copy link
Member

Thanks for submitting this bug. I've just reproduced it in on my end too, though with slightly different circumstances that the fix should also account for.

When I run jrnl --edit on an empty journal and add an entry:

[-1 entries deleted, 1 entry modified]

I think it should actually just say:

[1 entry added]

@piero-vic
Copy link
Contributor

Hi.
I think I've find the root of the problem.
It's on jrnl.py. Right here.

jrnl/jrnl/jrnl.py

Lines 276 to 296 in 44edb9b

def _print_edited_summary(journal, old_stats, **kwargs):
stats = {
"deleted": old_stats["count"] - len(journal),
"modified": len([e for e in journal.entries if e.modified]),
}
prompts = []
if stats["deleted"]:
prompts.append(
f"{stats['deleted']} {_pluralize_entry(stats['deleted'])} deleted"
)
if stats["modified"]:
prompts.append(
f"{stats['modified']} {_pluralize_entry(stats['modified'])} modified"
)
if prompts:
print(f"[{', '.join(prompts).capitalize()}]", file=sys.stderr)

I'm new to Python and open source but I think I can fix it. Can I work on this issue?

@micahellison
Copy link
Member

I'm new to Python and open source but I think I can fix it. Can I work on this issue?

Yes please, feel free to submit a PR and let us know if you have any questions!

I think to fully resolve this issue, a resolution should:

  • fix the bug
  • test for this in BDD (let us know if you need help)
    • this should include scenarios for all journal types (regular, directory, encrypted, DayOne)

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants