Skip to content

fix: resolve asyncpg str vs datetime TypeError in invite key creation#315

Merged
Agentscreator merged 2 commits into
Agentscreator:mainfrom
ismaeldouglasdev:fix/datetime-isoformat-asyncpg
May 22, 2026
Merged

fix: resolve asyncpg str vs datetime TypeError in invite key creation#315
Agentscreator merged 2 commits into
Agentscreator:mainfrom
ismaeldouglasdev:fix/datetime-isoformat-asyncpg

Conversation

@ismaeldouglasdev

@ismaeldouglasdev ismaeldouglasdev commented May 22, 2026

Copy link
Copy Markdown

Summary

Fixes asyncpg.exceptions.DataError when calling engram_init / engram_status / rotate_invite_key — the expiry datetime was serialized to an ISO string via .isoformat(), but asyncpg's TIMESTAMPTZ columns expect a datetime.datetime object.

Root Cause

Three call sites called .isoformat() on the expiry datetime before passing it to storage:

  1. server.py:engram_init (L532)
  2. server.py:engram_status (L361)
  3. engine.py:rotate_invite_key (L3072)

Additionally, the type hints in storage.py (base + SQLiteStorage) and postgres_storage.py declared expires_at: str | None, misleading callers into thinking strings were acceptable for the Postgres backend.

Changes

Commit 1 — Type hints

  • storage.py: Storage.insert_invite_key (base class) + SQLiteStorage.insert_invite_key: expires_at: str | Nonedatetime | None
  • postgres_storage.py: PostgresStorage.insert_invite_key: expires_at: str | Nonedatetime | None

Commit 2 — Call sites

  • server.py lines 361, 532: removed .isoformat()
  • engine.py line 3072: removed .isoformat()

Why SQLiteStorage still has .isoformat()

SQLite uses TEXT columns, so the SQLiteStorage implementation correctly continues to call .isoformat() internally — that's its concern, not the caller's. The interface now accurately reflects both backends' requirements.

Verification

  • All type hints confirmed as datetime | None (not str | None)
  • No .isoformat() calls remain in the Postgres-bound insert_invite_key paths
  • SQLiteStorage correctly retains its internal .isoformat() for TEXT column storage
  • All imports and module-level AST verification pass

Summary by CodeRabbit

  • Bug Fixes
    • Corrected invite key expiration timestamp calculations to ensure accurate date computations across the system.

Review Change Stack

Ismael Dev and others added 2 commits May 22, 2026 00:43
The type hints for expires_at parameter in insert_invite_key were str|None, but asyncpg expects datetime.datetime for TIMESTAMPTZ columns. This caused engram_init to fail with asyncpg.exceptions.DataError.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
server.py (engram_status, engram_init) and engine.py (rotate_invite_key) called .isoformat() on expiry datetimes, converting them to str. asyncpg then rejected these strings for TIMESTAMPTZ columns. The storage layer now receives raw datetime objects, matching asyncpg's expectations.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@vercel

vercel Bot commented May 22, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the agentscreator's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4135cfab-b5d7-4ad0-bf6d-30f7004b1197

📥 Commits

Reviewing files that changed from the base of the PR and between cab14fe and 750d25e.

📒 Files selected for processing (4)
  • src/engram/engine.py
  • src/engram/postgres_storage.py
  • src/engram/server.py
  • src/engram/storage.py

📝 Walkthrough

Walkthrough

Storage interfaces and implementations updated to accept datetime | None instead of str | None for invite key expiration timestamps. SQLiteStorage converts datetime to ISO strings for database storage. Server and engine timestamp calculations corrected to produce timezone-aware datetime objects.

Changes

Invite key expiration timestamp handling

Layer / File(s) Summary
Storage interface type update
src/engram/storage.py, src/engram/postgres_storage.py
BaseStorage and PostgresStorage insert_invite_key signatures updated to accept expires_at: datetime | None instead of str | None.
SQLiteStorage datetime-to-string conversion
src/engram/storage.py
SQLiteStorage.insert_invite_key converts incoming datetime objects to ISO format strings before inserting into the database.
Server and engine timestamp creation
src/engram/server.py, src/engram/engine.py
Server timestamp calculations in engram_status and engram_init produce timezone-aware datetime objects; rotate_invite_key datetime construction corrected.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Timestamps once lived as strings so plain,
Now datetime objects dance through the chain,
From server to storage, with care they flow,
SQLite converts them to strings we know,
A coordinated hop, both type-safe and true! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main issue being fixed: resolving a TypeError with asyncpg related to datetime vs string type mismatches in invite key creation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@Agentscreator Agentscreator merged commit bb8f961 into Agentscreator:main May 22, 2026
5 of 7 checks passed
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.

2 participants