Skip to content

fix(backend): coerce raw ISO-string timestamps on action-item read (#22181) - #22359

Merged
kodjima33 merged 1 commit into
mainfrom
watchdog/issue-22181-action-item-sort-key-string-timestamp
Oct 19, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
watchdog/issue-22181-action-item-sort-key-string-timestamp

Conversation

@kodjima33

@kodjima33 kodjima33 commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A row written before write-path timestamp normalization existed (or by an external integration/migration that bypassed it) can still have due_at or created_at stored as a raw ISO string in Firestore. prepare_action_item_for_read (backend/database/action_item_codec.py) already coerced datetime-like values to UTC via .timestamp(), but left plain strings untouched. _action_item_list_sort_key then compares that string against a datetime, raising TypeError: '<' not supported between instances of 'str' and 'datetime.datetime' — 500ing every caller of the action-items list (GET /v1/action-items, MCP get_action_items, get_pending_apple_reminders_sync's synced_items sort by updated_at, etc). Refs #22181.

Root cause

  • prepare_action_item_for_write already normalizes these fields on write (parses ISO strings, attaches UTC, drops malformed values) — confirmed by backend/tests/unit/test_action_items_date_coercion.py.
  • prepare_action_item_for_read is the one shared read-side normalization point used by every reader (list, get, batch, sync), but its coercion loop only handled values with a .timestamp() method, silently leaving a raw string alone.
  • Any document whose due_at/created_at predates that write-path normalization, or was written by a path that bypasses it, surfaces a string at read time and crashes every sort that compares it against a datetime.

Fix

Mirror the write-side coercion in prepare_action_item_for_read: parse an ISO string the same way (datetime.fromisoformat, attach UTC if naive), and drop the field instead of raising on a malformed value — same fail-open policy the write path already uses.

What I tested

  • New backend/tests/unit/test_action_items_read_string_timestamps.py: ISO-string coercion, malformed-string drop, date-only string, and two end-to-end sorts (_action_item_list_sort_key over mixed string/datetime due_at and created_at) that reproduce the reported crash and now pass.
  • Ran all 20 action_items-related unit test files individually with the fix applied — all pass. (One file, test_action_items_pagination_order.py, fails when run in the same pytest session as several sibling files due to a pre-existing fixture-order issue; reproduced identically with this fix reverted, so it is unrelated to this change.)

Failure-Class: FC-malformed-doc-read

🤖 automated by hourly watchdog — tested and merged

View guided diff Turn on auto-fix

…22181)

A row written before write-path timestamp normalization existed (or by an
external integration/migration that bypassed it) can still have due_at or
created_at stored as a raw string in Firestore. prepare_action_item_for_read
already coerced datetime-like values but left strings untouched, so
_action_item_list_sort_key crashed with TypeError comparing a string against
a datetime, 500ing GET /v1/action-items and every other reader of the list.

Mirror the write-side coercion (prepare_action_item_for_write) at the read
boundary: parse ISO strings to UTC datetimes, drop unparseable ones.
@kodjima33
kodjima33 merged commit 0d8e125 into main Oct 19, 2026
62 checks passed
@kodjima33
kodjima33 deleted the watchdog/issue-22181-action-item-sort-key-string-timestamp branch October 19, 2026 04:19
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