Skip to content

fix: Add missing comment argument to Activity constructor#7

Merged
loganthomas merged 1 commit intodevfrom
fix/activity-comment-argument
Jan 7, 2026
Merged

fix: Add missing comment argument to Activity constructor#7
loganthomas merged 1 commit intodevfrom
fix/activity-comment-argument

Conversation

@loganthomas
Copy link
Copy Markdown
Owner

Summary

This PR fixes a TypeError that occurs when running utt balance due to a missing comment argument in the Activity constructor call.

Problem

When running utt balance, users encounter the following error:

Traceback (most recent call last):
  File ".../utt/__main__.py", line 39, in main
    _v1._private.container[command.handler_class]()
  File ".../utt/plugins/balance.py", line 93, in __call__
    worked_today = self._calculate_worked_time(today, today)
  ...
  File ".../utt/plugins/balance.py", line 211, in _entries_to_activities
    yield _v1.Activity(
          ^^^^^^^^^^^^^
TypeError: Activity.__init__() missing 1 required positional argument: 'comment'

Root Cause

The utt library's API has been updated. Both Entry and Activity classes now include a comment parameter:

  • Entry.__init__(self, entry_datetime, name, is_current_entry, comment: Optional[str])
  • Activity.__init__(self, name, start, end, is_current_activity, comment: Optional[str])

The balance plugin was creating Activity objects with only 4 arguments, missing the required comment parameter.

Solution

Code Fix

Updated _entries_to_activities() in src/utt/plugins/balance.py to pass the entry's comment through to the Activity:

# Before (broken)
yield _v1.Activity(
    next_entry.name,
    prev_entry.datetime,
    next_entry.datetime,
    False,
)

# After (fixed)
yield _v1.Activity(
    next_entry.name,
    prev_entry.datetime,
    next_entry.datetime,
    False,
    next_entry.comment,  # Pass through the comment
)

Test Updates

  1. Updated all Entry constructor calls in tests/test_balance.py to include the comment parameter (32 instances), as it is now required by the utt API.

  2. Added regression tests to ensure this issue doesn't recur:

    • test_activity_preserves_entry_comment: Verifies that comments are properly passed from Entry to Activity
    • test_activity_handles_none_comment: Verifies that None comments are handled gracefully

Testing

All 47 tests pass with 100% coverage:

============================= test session starts ==============================
collected 47 items
...
============================== 47 passed in 1.02s ==============================

The utt balance command now works correctly:

$ utt balance
┏━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┓
┃              ┃ Worked ┃ Remaining ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━┩
│ Today        │   0h00 │      8h00 │
│ Since Sunday │   0h00 │     40h00 │
└──────────────┴────────┴───────────┘

Background: What is the comment field?

The comment field is a utt feature that allows users to add annotations to time entries:

utt add "work: feature-xyz" -c "Implemented login flow for new auth system"

This provides additional context without cluttering the task name, and comments appear in utt report output.

The utt library's Activity class now requires a 'comment' parameter.
This change updates the _entries_to_activities method to pass
next_entry.comment when creating Activity objects.

Also updates all Entry constructor calls in tests to include the
comment parameter (now required by the utt API) and adds regression
tests to ensure the comment is properly passed through.
@loganthomas loganthomas merged commit 6bd44a4 into dev Jan 7, 2026
4 checks passed
@loganthomas loganthomas deleted the fix/activity-comment-argument branch January 7, 2026 21:45
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.

1 participant