fix(dialog_cache): read cached_at as UTC-aware (naive/aware TypeError #1291) - #1293
Merged
axisrow merged 1 commit intoJul 23, 2026
Merged
Conversation
…ypeError (#1291) `dialog_cache.cached_at` has a schema DEFAULT of `datetime('now')`, which yields a naive string without a UTC offset. Rows inserted without an explicit cached_at therefore reached `get_cached_at` as naive datetimes, and `_get_db_cached_dialogs` (pool_dialogs) crashed on `datetime.now(timezone.utc) - cached_at` with TypeError. Fix at the row→model boundary: parse through `parse_utc_datetime`, which normalizes naive values to UTC. Latent — the normal write path already emits aware isoformat strings, so this only triggers when the schema DEFAULT fills cached_at. Regression tests: - repo-level: schema-DEFAULT row reads back UTC-aware; normal write path preserves time without drift. - pool_dialogs e2e: real DB + schema-DEFAULT row no longer raises on age subtraction (proven red on pre-fix code with the exact TypeError). Co-Authored-By: Claude <noreply@anthropic.com>
Owner
Author
📋 Review summary — all cyclesReviewed locally in cycle-review local mode: built-in
Totals: 0 FIX, 0 SKIP, 0 UNVERIFIED. Clean first round. Notes:
|
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.
What
Fixes the latent naive/aware
TypeErrorin the dialog-cache age computation found by audit (a "beyond scope" finding of #1234 review).Closes #1291.
Root cause
dialog_cache.cached_athas a schema DEFAULT ofdatetime('now')(src/database/schema.py:316), which yields a naive string without a UTC offset. Rows inserted without an explicitcached_attherefore reachedDialogCacheRepository.get_cached_atas naive datetimes, and_get_db_cached_dialogs(src/telegram/pool_dialogs.py:402) crashed on:→ the dialog warm/refresh path crashes whenever the schema DEFAULT fills
cached_at. Latent only because the normal write path (replace_dialogs) emits awareisoformat()strings.Fix
Normalize at the row→model boundary:
get_cached_atnow reads throughparse_utc_datetime, which treats naive values as UTC. Minimal, single-method change; all consumers (pool_dialogs, web/CLI/agent dialogs handlers) benefit.TDD cycle (per request)
test_get_db_cached_dialogs_survives_naive_cached_at— real DB row relying on the schema DEFAULT raised the exactTypeErroron pre-fix code inpool_dialogs.py:402.Tests
tests/repositories/test_dialog_cache_repository.py(new) — schema-DEFAULT row reads back UTC-aware; normal write path preserves time without drift.tests/test_main_client_pool_collector_paths.py—_get_db_cached_dialogse2e against a real DB no longer raises.ruff checkclean on changed files.Risk / follow-up
Low. This is the recurring "naive/aware datetime at the row→model boundary" bug class (cf. #1234/pool_dialogs); normalizing on read is the project's established direction from the issue.
🤖 Generated with Claude Code