Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

refactor(proxy): type the race helper's db against a Protocol

Yuneng Jiang570b34988b12
diff --git a/litellm/proxy/db/create_views.py b/litellm/proxy/db/create_views.py
index 47207adee80..6743f30f400 100644
--- a/litellm/proxy/db/create_views.py
+++ b/litellm/proxy/db/create_views.py
@@ -1,9 +1,20 @@
-from typing import Any, Final
+from typing import Any, Final, Protocol
from litellm import verbose_logger
_db = Any
+
+class SupportsExecuteRaw(Protocol):
+ """The one database operation create_view_tolerating_race needs.
+
+ Narrower than the `_db = Any` the rest of this module still uses, so the
+ helper's contract is checkable at its call sites without retyping every
+ function here.
+ """
+
+ async def execute_raw(self, query: str, *args: object) -> int: ...
+
# Markers that indicate a view/relation does not yet exist in the database.
# Keeping these in one place avoids repeating the check across all view blocks
# and prevents overly broad matches (e.g. bare 'undefined' would also match
@@ -15,7 +26,9 @@ _VIEW_NOT_FOUND_MARKERS: Final = ("does not exist", "no such table", "undefined
_VIEW_ALREADY_EXISTS_MARKERS: Final = ("already exists", "duplicate object", "duplicate table")
-async def create_view_tolerating_race(db: _db, view_name: str, ddl: str) -> None:
+async def create_view_tolerating_race(
+ db: SupportsExecuteRaw, view_name: str, ddl: str
+) -> None:
"""
Create a view, treating "a concurrent creator won" as success.