Skip to content

fix: use model_dump(mode="json") so datetime fields are JSON-serializable in activity cache#32

Merged
bin101 merged 1 commit into
mainfrom
fix/activity-cache-datetime-serialization
Jul 1, 2026
Merged

fix: use model_dump(mode="json") so datetime fields are JSON-serializable in activity cache#32
bin101 merged 1 commit into
mainfrom
fix/activity-cache-datetime-serialization

Conversation

@bin101

@bin101 bin101 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Activity.start_date is a datetime object; model_dump() (Python mode) kept it as-is, causing json.dumps in store._write_json_atomic to raise TypeError: Object of type datetime is not JSON serializable
  • The crash happened after every successful kudos run, as a background-task exception in the ASGI stack
  • Fix: use model_dump(mode="json") in engine.py (line 197), identical to the already-correct path in routes.py (line 378)
  • Adds a regression test in tests/unit/test_engine_cache.py that asserts result.activities is fully JSON-serialisable when start_date is set

Test plan

  • pytest tests/unit/test_engine_cache.py — new test green
  • Full suite: 368 passed, 0 warnings, coverage 86 %
  • ruff check, ruff format --check, mypy — all clean

🤖 Generated with Claude Code

…able in activity cache

Activity.start_date is a datetime object; the plain model_dump() call kept it
as a Python datetime, causing a TypeError when store._write_json_atomic called
json.dumps().  Align with the already-correct path in routes.py by passing
mode="json", which serialises datetime to ISO strings.

Adds a regression test that verifies result.activities is fully JSON-serializable
even when start_date is set.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bin101 bin101 merged commit 452bf61 into main Jul 1, 2026
1 check passed
@bin101 bin101 deleted the fix/activity-cache-datetime-serialization branch July 1, 2026 06:33
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