Skip to content

Commit 971a996

Browse files
Handle duplicate model rows when resolving routing targets
1 parent 429d683 commit 971a996

File tree

7 files changed

+47
-7
lines changed

7 files changed

+47
-7
lines changed

backend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Backend sync worker service."""
22

3-
__version__ = "0.6.28"
3+
__version__ = "0.6.29"

frontend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Frontend API and UI service."""
22

3-
__version__ = "0.6.28"
3+
__version__ = "0.6.29"

litellm_updater/crud.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,29 @@ async def get_model_by_provider_and_name(
227227
result = await session.execute(
228228
select(Model)
229229
.where(Model.provider_id == provider_id, Model.model_id == model_id)
230+
.order_by(
231+
Model.is_orphaned.asc(),
232+
Model.last_seen.desc(),
233+
Model.updated_at.desc(),
234+
Model.id.desc(),
235+
)
230236
.options(selectinload(Model.provider))
231237
)
232-
return result.scalar_one_or_none()
238+
matches = list(result.scalars().all())
239+
if not matches:
240+
return None
241+
if len(matches) > 1:
242+
import logging
243+
244+
logger = logging.getLogger(__name__)
245+
logger.warning(
246+
"Duplicate model rows found for provider_id=%s model_id=%s (count=%s); using id=%s",
247+
provider_id,
248+
model_id,
249+
len(matches),
250+
matches[0].id,
251+
)
252+
return matches[0]
233253

234254

235255
async def create_model(

proxy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.6.28"
1+
__version__ = "0.6.29"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "litellm-companion"
3-
version = "0.6.28"
3+
version = "0.6.29"
44
description = "Synchronize models from Ollama or OpenAI-compatible endpoints into LiteLLM"
55
authors = [
66
{name = "LiteLLM Companion Authors", email = "dev@example.com"}

shared/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Shared code between backend and frontend services."""
22

3-
__version__ = "0.6.28"
3+
__version__ = "0.6.29"

shared/crud.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,29 @@ async def get_model_by_provider_and_name(
269269
result = await session.execute(
270270
select(Model)
271271
.where(Model.provider_id == provider_id, Model.model_id == model_id)
272+
.order_by(
273+
Model.is_orphaned.asc(),
274+
Model.last_seen.desc(),
275+
Model.updated_at.desc(),
276+
Model.id.desc(),
277+
)
272278
.options(selectinload(Model.provider))
273279
)
274-
return result.scalar_one_or_none()
280+
matches = list(result.scalars().all())
281+
if not matches:
282+
return None
283+
if len(matches) > 1:
284+
import logging
285+
286+
logger = logging.getLogger(__name__)
287+
logger.warning(
288+
"Duplicate model rows found for provider_id=%s model_id=%s (count=%s); using id=%s",
289+
provider_id,
290+
model_id,
291+
len(matches),
292+
matches[0].id,
293+
)
294+
return matches[0]
275295

276296

277297
async def create_model(

0 commit comments

Comments
 (0)