fix(endpoint): import ModelEndpoint from core database
ModelEndpoint is defined in core.database, not src.database. The wrong import silently prevented the module from loading in deployment configurations that do not have a src/database.py shim, resulting in an ImportError at startup. Also adds a warning log when resolve_endpoint finds no usable model (all models hidden or the list is empty), making the otherwise-silent failure visible in operator logs. The test_auth_regressions stub for src.endpoint_resolver was missing the build_models_url attribute, which caused test collection errors. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import subprocess
|
|||||||
from typing import Optional, Tuple, Dict
|
from typing import Optional, Tuple, Dict
|
||||||
from urllib.parse import urlparse, urlunparse
|
from urllib.parse import urlparse, urlunparse
|
||||||
|
|
||||||
from src.database import SessionLocal, ModelEndpoint
|
from core.database import SessionLocal, ModelEndpoint
|
||||||
from src.llm_core import _detect_provider, _host_match
|
from src.llm_core import _detect_provider, _host_match
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -285,6 +285,8 @@ def resolve_endpoint(
|
|||||||
# If no (usable) model specified, pick the first enabled chat model.
|
# If no (usable) model specified, pick the first enabled chat model.
|
||||||
if not model:
|
if not model:
|
||||||
model = _first_chat_model(_endpoint_enabled_models(ep)) or ""
|
model = _first_chat_model(_endpoint_enabled_models(ep)) or ""
|
||||||
|
if not model and not fallback_model:
|
||||||
|
logger.warning('[resolve_endpoint] no usable model (all models hidden or list empty)')
|
||||||
|
|
||||||
return chat_url, model or fallback_model, headers
|
return chat_url, model or fallback_model, headers
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -81,13 +81,13 @@ def _auth_regressions_stubs(monkeypatch):
|
|||||||
resolve_endpoint=MagicMock(return_value=("", "", {})),
|
resolve_endpoint=MagicMock(return_value=("", "", {})),
|
||||||
normalize_base=MagicMock(),
|
normalize_base=MagicMock(),
|
||||||
build_chat_url=MagicMock(),
|
build_chat_url=MagicMock(),
|
||||||
|
build_models_url=MagicMock(),
|
||||||
build_headers=MagicMock(),
|
build_headers=MagicMock(),
|
||||||
)
|
)
|
||||||
monkeypatch.setitem(sys.modules, "core.database", db)
|
monkeypatch.setitem(sys.modules, "core.database", db)
|
||||||
monkeypatch.setitem(sys.modules, "core.auth", auth)
|
monkeypatch.setitem(sys.modules, "core.auth", auth)
|
||||||
monkeypatch.setitem(sys.modules, "src.endpoint_resolver", ep)
|
monkeypatch.setitem(sys.modules, "src.endpoint_resolver", ep)
|
||||||
|
|
||||||
|
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user