fix(tool-registry): pass naive UTC datetime to fix PostgreSQL timestamp error on v1.82.0-stable - #23481
Merged
joereyna merged 1 commit intoMar 14, 2026
Conversation
…mp type error
`datetime.now(timezone.utc).isoformat()` produces a timezone-aware string
("2026-03-12T13:34:30+00:00") that PostgreSQL rejects when binding to a
`timestamp without time zone` column via execute_raw, logging:
ERROR: column "created_at" is of type timestamp without time zone
but expression is of type text
Replacing with `.replace(tzinfo=None)` produces a timezone-naive UTC datetime
that Prisma passes natively without needing ::timestamp casts. The stored
value is correct because the source is always UTC.
Fixes the ~185 errors/hour reported against v1.82.0-stable with PostgreSQL.
Applies to both batch_upsert_tools and update_tool_policy call sites.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThis is a minimal, targeted fix for a PostgreSQL type-binding error in Key points:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/db/tool_registry_writer.py | Two call sites changed from .isoformat() (returning a timezone-aware string) to .replace(tzinfo=None) (returning a naive datetime object). Fix is correct and consistent; minor pre-existing issue of now being created inside the loop is unrelated to this PR. |
Sequence Diagram
sequenceDiagram
participant LLM as LLM Response
participant TRW as tool_registry_writer
participant Prisma as Prisma Client
participant PG as PostgreSQL
LLM->>TRW: discovered tool names
TRW->>TRW: now = datetime.now(UTC).replace(tzinfo=None)<br/>(naive UTC datetime)
TRW->>Prisma: execute_raw(INSERT ... $8=now, ...)
Prisma->>PG: bind now → timestamp without time zone ✅
PG-->>Prisma: OK / conflict → increment call_count
Prisma-->>TRW: success
TRW-->>LLM: upserted
note over TRW,PG: Previously: .isoformat() produced "2026-03-12T13:34:30+00:00"<br/>→ PostgreSQL rejected text → timestamp cast ❌
Last reviewed commit: a73b1ca
joereyna
merged commit Mar 14, 2026
8eb2daf
into
BerriAI:litellm_stable_v1_82_0
4 of 5 checks passed
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
Fixes continuous
tool_registry_writer batch_upsert_tools error: ERROR: column "created_at" is of type timestamp without time zone but expression is of type texton v1.82.0-stable with PostgreSQL.datetime.now(timezone.utc).isoformat()produces a timezone-aware string ("2026-03-12T13:34:30+00:00") that PostgreSQL rejects when binding to atimestamp without time zonecolumn viaexecute_raw.replace(tzinfo=None)to produce a timezone-naive UTC datetime that Prisma passes natively — no::timestampcast needed, no schema changes requiredbatch_upsert_toolsandupdate_tool_policycall sitesImpact
Reported as ~185 errors/hour on Cloud Run + Cloud SQL PostgreSQL (v1.82.0-stable). Error fires every ~8 seconds for any deployment with tool calling enabled.
Related
::timestampcast); closed by author once they confirmed main had a better fixmainis a full Prisma ORM refactor ([Feat] Add Tool Policies for AI Gateway #22732) with schema changes (call_policy→input_policy/output_policy) — not backport-safe to stableTest plan
tests/test_litellm/proxy/db/test_tool_registry_writer.py— 11/11 passing locallytool_registry_writer batch_upsert_tools errorno longer appears in logs