Skip to content

Conversation

@MariusWirtz
Copy link
Collaborator

Fixes #1308

@MariusWirtz MariusWirtz requested a review from Copilot November 7, 2025 11:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in the ChoreService.update() method and updates the corresponding test to use the correct test fixture. The changes address an UnboundLocalError that would occur when updating a chore with no tasks.

  • Fixes UnboundLocalError when updating chores without tasks by initializing the loop variable i
  • Updates test to use chore_name3 (chore without tasks) instead of chore_name1 (chore with tasks) for more accurate test coverage

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
TM1py/Services/ChoreService.py Initializes loop variable i to prevent UnboundLocalError when iterating over empty task list
Tests/ChoreService_test.py Updates test to use appropriate test fixture (chore_name3 without tasks) for testing chore updates without tasks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


# 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.
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

Successfully merging this pull request may close these issues.

Chores with no tasks fail to update

2 participants