Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions litellm/proxy/db/tool_registry_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def batch_upsert_tools(
data = [item for item in items if item.get("tool_name")]
if not data:
return
now = datetime.now(timezone.utc)
now = datetime.now(timezone.utc).isoformat()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

table = prisma_client.db.litellm_tooltable
for item in data:
tool_name = item.get("tool_name", "")
Expand Down Expand Up @@ -171,7 +171,7 @@ async def update_tool_policy(
"""Update input_policy and/or output_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)
now = datetime.now(timezone.utc).isoformat()

create_data: dict = {
"tool_id": str(uuid.uuid4()),
Expand Down
9 changes: 8 additions & 1 deletion tests/test_litellm/proxy/db/test_tool_registry_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ async def test_batch_upsert_tools_calls_upsert():
assert call_kw["data"]["create"]["output_policy"] == "untrusted"
assert call_kw["data"]["create"]["call_count"] == 1
assert call_kw["data"]["update"]["call_count"] == {"increment": 1}
assert "updated_at" in call_kw["data"]["update"]
# Timestamps should be ISO strings, not datetime objects.
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)


@pytest.mark.asyncio
Expand Down Expand Up @@ -194,6 +197,10 @@ async def test_update_tool_policy_calls_upsert_then_get_tool():
assert call_kw["where"] == {"tool_name": "my_tool"}
assert call_kw["data"]["update"]["input_policy"] == "blocked"
assert call_kw["data"]["update"]["updated_by"] == "admin"
# created_at / updated_at must be ISO strings for Postgres compatibility.
assert isinstance(call_kw["data"]["create"]["created_at"], str)
assert isinstance(call_kw["data"]["create"]["updated_at"], str)
assert isinstance(call_kw["data"]["update"]["updated_at"], str)
prisma.db.litellm_tooltable.find_unique.assert_awaited_with(
where={"tool_name": "my_tool"}
)
Expand Down
Loading