Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions TM1py/Services/ChoreService.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def update(self, chore: Chore, **kwargs):

# Update Tasks individually
task_old_count = self._get_tasks_count(chore.name)
i = 0
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing i = 0 prevents UnboundLocalError when chore.tasks is empty, but this may cause incorrect behavior. If a chore currently has tasks but the update sets chore.tasks = [] (removing all tasks), the deletion loop on line 182 will be range(1, task_old_count) instead of range(0, task_old_count), potentially leaving the first task undeleted. Consider initializing i = -1 instead, so that i + 1 = 0 when no tasks are present.

Suggested change
i = 0
i = -1

Copilot uses AI. Check for mistakes.
for i, task_new in enumerate(chore.tasks):
if i >= task_old_count:
self._add_task(chore.name, task_new, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions Tests/ChoreService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_update_active_chore(self):

def test_update_chore_without_tasks(self):
# get chore
c = self.tm1.chores.get(self.chore_name1)
c = self.tm1.chores.get(self.chore_name3)
# update all properties
# update start time
start_time = datetime(2023, 4, 5, 12, 5, 30)
Expand All @@ -332,9 +332,9 @@ def test_update_chore_without_tasks(self):
# update chore in TM1
self.tm1.chores.update(c)
# get chore and check all properties
c = self.tm1.chores.get(chore_name=self.chore_name1)
c = self.tm1.chores.get(chore_name=self.chore_name3)
self.assertEqual(c._start_time._datetime.replace(microsecond=0), start_time.replace(microsecond=0))
self.assertEqual(c._name, self.chore_name1)
self.assertEqual(c._name, self.chore_name3)
self.assertEqual(c._dst_sensitivity, True)
self.assertEqual(c._active, False)
self.assertEqual(c._execution_mode, Chore.SINGLE_COMMIT)
Expand Down
Loading