From a73b1cad1ecfcebd787e69a3b504c82ff5c19622 Mon Sep 17 00:00:00 2001 From: joereyna Date: Thu, 12 Mar 2026 12:42:31 -0700 Subject: [PATCH] fix(tool-registry): pass naive UTC datetime to fix PostgreSQL timestamp 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 --- litellm/proxy/db/tool_registry_writer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/db/tool_registry_writer.py b/litellm/proxy/db/tool_registry_writer.py index 4e0a8095a08..dd6a6960157 100644 --- a/litellm/proxy/db/tool_registry_writer.py +++ b/litellm/proxy/db/tool_registry_writer.py @@ -62,7 +62,7 @@ async def batch_upsert_tools( key_hash = item.get("key_hash") team_id = item.get("team_id") key_alias = item.get("key_alias") - now = datetime.now(timezone.utc).isoformat() + now = datetime.now(timezone.utc).replace(tzinfo=None) await prisma_client.db.execute_raw( 'INSERT INTO "LiteLLM_ToolTable" ' "(tool_id, tool_name, origin, call_policy, call_count, created_by, updated_by, key_hash, team_id, key_alias, created_at, updated_at) " @@ -140,7 +140,7 @@ async def update_tool_policy( """Update the call_policy for a tool. Upserts the row if it does not exist yet.""" try: _updated_by = updated_by or "system" - now = datetime.now(timezone.utc).isoformat() + now = datetime.now(timezone.utc).replace(tzinfo=None) await prisma_client.db.execute_raw( 'INSERT INTO "LiteLLM_ToolTable" (tool_id, tool_name, call_policy, created_by, updated_by, created_at, updated_at) ' "VALUES ($4, $1, $2, $3, $3, $5, $5) "