fix: use ISO timestamps for tool registry Prisma writes - #23732
fix: use ISO timestamps for tool registry Prisma writes#23732milan-berri wants to merge 3 commits into
Conversation
Made-with: Cursor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes a Postgres type-mismatch error (#23585) by converting timezone-aware Key changes:
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/db/tool_registry_writer.py | Two one-line changes convert datetime.now(timezone.utc) to .isoformat() at lines 86 and 174, eliminating the Postgres type-mismatch when timezone-aware datetime objects were passed directly into Prisma writes for LiteLLM_ToolTable. Fix is minimal, correct, and covers all affected write paths. |
| tests/test_litellm/proxy/db/test_tool_registry_writer.py | Adds isinstance(..., str) assertions in two existing tests to verify that timestamp values written to Prisma are ISO strings, not datetime objects. All tests remain mock-only (no real network calls). The _mock_row helper still uses datetime objects for its defaults, which is correct since those simulate values returned from Prisma (read path), not values sent to Prisma (write path). |
Sequence Diagram
sequenceDiagram
participant Caller
participant batch_upsert_tools
participant update_tool_policy
participant Prisma
participant Postgres
Note over batch_upsert_tools,update_tool_policy: now = datetime.now(timezone.utc).isoformat()
Caller->>batch_upsert_tools: items: List[ToolDiscoveryQueueItem]
batch_upsert_tools->>Prisma: table.upsert(data={create: {last_used_at: "2026-03-20T10:00:00+00:00"}, update: {updated_at: "...", last_used_at: "..."}})
Prisma->>Postgres: INSERT ... ON CONFLICT ... (ISO string timestamps)
Postgres-->>Prisma: OK
Caller->>update_tool_policy: tool_name, input_policy, output_policy
update_tool_policy->>Prisma: table.upsert(data={create: {created_at: "...", updated_at: "..."}, update: {updated_at: "..."}})
Prisma->>Postgres: INSERT ... ON CONFLICT ... (ISO string timestamps)
Postgres-->>Prisma: OK
update_tool_policy->>Prisma: find_unique(where={tool_name: ...})
Prisma-->>update_tool_policy: LiteLLM_ToolTableRow
update_tool_policy-->>Caller: LiteLLM_ToolTableRow
Last reviewed commit: "Merge branch 'main' ..."
| if not data: | ||
| return | ||
| now = datetime.now(timezone.utc) | ||
| now = datetime.now(timezone.utc).isoformat() |
There was a problem hiding this comment.
No test asserting ISO string format
The fix is correct, but none of the existing tests in test_tool_registry_writer.py assert that the timestamp values passed to Prisma are actually strings (not datetime objects). For example, test_batch_upsert_tools_calls_upsert checks "updated_at" in call_kw["data"]["update"] but not its type.
Adding an explicit assertion would serve as the evidence of resolution called for in the pre-submission checklist (which still shows the testing item unchecked):
assert isinstance(call_kw["data"]["create"]["last_used_at"], str)
assert isinstance(call_kw["data"]["update"]["updated_at"], str)
assert isinstance(call_kw["data"]["update"]["last_used_at"], str)The same gap exists in test_update_tool_policy_calls_upsert_then_get_tool for created_at and updated_at values at line 174 in update_tool_policy.
Both occurrences of now in this file are affected: line 86 (batch_upsert_tools) and line 174 (update_tool_policy).
Rule Used: What: Ensure that any PR claiming to fix an issue ... (source)
Made-with: Cursor
Relevant issues
The global tool registry and tool policy wiring were introduced in:
feat(proxy): tool policies - auto-discover tools + policy enforcement guardrail(PR feat(proxy): tool policies - auto-discover tools + policy enforcement guardrail #22041)[Feat] Add Tool Policies for AI Gateway(PR [Feat] Add Tool Policies for AI Gateway #22732)These changes started passing timezone-aware
datetimeobjects through Prisma intoLiteLLM_ToolTable, which surfaces as the Postgres type mismatch described in #23585.This PR completes and generalizes the partial fix proposed in #23586 by applying the ISO conversion consistently to both
batch_upsert_toolsandupdate_tool_policy.Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🐛 Bug Fix