Repository navigation
fix(backend): coerce raw ISO-string timestamps on action-item read (#22181) - #22359
Merged
kodjima33 merged 1 commit intoOct 19, 2026
Merged
Conversation
…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
deleted the
watchdog/issue-22181-action-item-sort-key-string-timestamp
branch
October 19, 2026 04:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A row written before write-path timestamp normalization existed (or by an external integration/migration that bypassed it) can still have
due_atorcreated_atstored 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_keythen compares that string against adatetime, raisingTypeError: '<' not supported between instances of 'str' and 'datetime.datetime'— 500ing every caller of the action-items list (GET /v1/action-items, MCPget_action_items,get_pending_apple_reminders_sync'ssynced_itemssort byupdated_at, etc). Refs #22181.Root cause
prepare_action_item_for_writealready normalizes these fields on write (parses ISO strings, attaches UTC, drops malformed values) — confirmed bybackend/tests/unit/test_action_items_date_coercion.py.prepare_action_item_for_readis 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.due_at/created_atpredates 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 adatetime.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
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_keyover mixed string/datetimedue_atandcreated_at) that reproduce the reported crash and now pass.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