Skip to content

fix: convert datetime to ISO string for PostgreSQL timestamp compatibility - #23586

Closed
Jah-yee wants to merge 1 commit into
BerriAI:mainfrom
Jah-yee:fix/timestamp-type-mismatch
Closed

fix: convert datetime to ISO string for PostgreSQL timestamp compatibility#23586
Jah-yee wants to merge 1 commit into
BerriAI:mainfrom
Jah-yee:fix/timestamp-type-mismatch

Conversation

@Jah-yee

@Jah-yee Jah-yee commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Fixes timestamp type mismatch error in tool_registry_writer.py when inserting into LiteLLM_ToolTable. PostgreSQL expects timestamp format, not timezone-aware datetime objects.

Closes #23585

…ompatibility

Fixes timestamp type mismatch error in tool_registry_writer.py when
inserting into LiteLLM_ToolTable. PostgreSQL expects timestamp format
not timezone-aware datetime objects.

Closes BerriAI#23585
@vercel

vercel Bot commented Mar 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Error Error Mar 13, 2026 10:44pm

Request Review

@CLAassistant

CLAassistant commented Mar 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a PostgreSQL/Prisma timestamp compatibility error in batch_upsert_tools by converting datetime.now(timezone.utc) to its ISO 8601 string form via .isoformat(). While the fix addresses the immediate crash site, the change is incomplete — the sibling function update_tool_policy in the same file still passes raw timezone-aware datetime objects to Prisma for created_at and updated_at, leaving that code path exposed to the exact same error.

Key observations:

  • Partial fix: Only batch_upsert_tools (line 86) is updated; update_tool_policy (line 174) retains the original unpatched pattern.
  • No tests included: The PR does not include a test or other verifiable evidence that the fix resolves the reported issue, which is required by project conventions for bug-fix PRs.

Confidence Score: 3/5

  • The fix is correct at the call site it touches, but the same bug remains in update_tool_policy, meaning a different user-facing code path can still throw the same error.
  • Score reduced because the patch is incomplete: one of the two places in the file that write timestamps to Prisma is still using the un-fixed pattern, leaving a second code path broken. No tests are provided to confirm the fix.
  • litellm/proxy/db/tool_registry_writer.pyupdate_tool_policy at line 174 still needs the .isoformat() conversion.

Important Files Changed

Filename Overview
litellm/proxy/db/tool_registry_writer.py Partial fix for PostgreSQL timestamp compatibility: batch_upsert_tools is fixed, but update_tool_policy still passes a raw timezone-aware datetime object to Prisma, leaving the same bug unresolved in that code path.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[batch_upsert_tools called] --> B["now = datetime.now(timezone.utc).isoformat() ✅ FIXED"]
    B --> C[Prisma upsert with ISO string timestamp]
    C --> D[PostgreSQL accepts timestamp string]

    E[update_tool_policy called] --> F["now = datetime.now(timezone.utc) ❌ NOT FIXED"]
    F --> G[Prisma upsert with datetime object]
    G --> H[PostgreSQL type mismatch error]
Loading

Comments Outside Diff (1)

  1. litellm/proxy/db/tool_registry_writer.py, line 174 (link)

    Incomplete fix — same timestamp issue in update_tool_policy

    The batch_upsert_tools function is fixed, but the update_tool_policy function (lines 174–188) still uses a bare datetime.now(timezone.utc) object for created_at and updated_at. If the root cause is that PostgreSQL/Prisma rejects timezone-aware datetime objects directly, this function will trigger the same error when called. The fix should be applied consistently throughout the file.

Last reviewed commit: cac533c

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.

Tool Registry Writer: timestamp type mismatch error on LiteLLM_ToolTable INSERT

2 participants