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

Fix crash when creating first-ever Task #24

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix passing empty sequence to max
Previously, when there were no Tasks and `Tasks.generate_id` was called, the `max` function would throw a ValueError.

Now we check to see if the Task list is empty before generating a new id.
  • Loading branch information
ethall authored Jul 7, 2022
commit 9e3c9cc95330a4d048d53ca1d27fde76b12a8e86
2 changes: 2 additions & 0 deletions calcure/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ def move_task(self, number_from, number_to):

def generate_id(self):
"""Generate a id for a new item. The id is generated as maximum of existing ids plus one"""
if self.is_empty():
return 0
return max([item.item_id for item in self.items]) + 1


Expand Down