Ignore stale embedded model metadata when a node exposes an explicit model widget

This commit is contained in:
Dariusz L
2026-08-25 03:07:41 +02:00
parent cd626dedab
commit 1eb3af32be
2 changed files with 68 additions and 0 deletions
+17
View File
@@ -225,6 +225,15 @@ class LoadedModelsService:
return str(scope["subgraph_id"]) == str(ref.subgraph_id or "")
return True
def has_explicit_model_widget_ref(node):
"""Return whether the node already exposes a normal model widget."""
return any(
node_matches_ref(node, ref)
and ref.widget_index is not None
and not ref.extra_value("is_urn", False)
for ref in all_model_refs
)
# Collect all loaded models with their values
loaded_models = []
total_refs = len(all_model_refs)
@@ -353,6 +362,14 @@ class LoadedModelsService:
)
node_type = node.get("type", "")
if has_explicit_model_widget_ref(node):
# Standard loaders persist stale/default entries in
# properties.models. The analyzed widget reference is the
# authoritative active model for nodes with an explicit
# model widget; keep properties.models as a fallback for
# nodes that do not expose one.
continue
properties = node.get("properties", {})
if not isinstance(properties, dict):
properties = {}
+51
View File
@@ -177,6 +177,57 @@ async def test_loaded_models_route_includes_urn_and_embedded_models():
assert body["total"] == 2
@pytest.mark.asyncio
async def test_loaded_models_route_ignores_stale_embedded_metadata_for_widget_loader():
handlers, _ = _build_routes(
{
"available_models": [],
"model_refs": [
{
"original_path": (
r"KREA2\Krea2_Turbo_convrot_int8mixed.safetensors"
),
"node_id": 761,
"widget_index": 0,
"node_type": "UNETLoader",
"category": "diffusion_models",
}
],
}
)
handler = handlers[("POST", "/model_resolver/loaded")]
workflow = {
"nodes": [
{
"id": 761,
"type": "UNETLoader",
"widgets_values": [
r"KREA2\Krea2_Turbo_convrot_int8mixed.safetensors",
"default",
],
"properties": {
"models": [
{
"name": "z_image_turbo_bf16.safetensors",
"directory": "diffusion_models",
}
]
},
}
]
}
with patch.dict(sys.modules, {"folder_paths": None}):
response = await handler(_request({"workflow": workflow}))
body = json.loads(response.text)
assert response.status == 200
assert body["total"] == 1
assert [model["name"] for model in body["loaded_models"]] == [
"Krea2_Turbo_convrot_int8mixed.safetensors"
]
@pytest.mark.asyncio
async def test_loaded_models_route_returns_error_when_inventory_fails():
handlers, values = _build_routes()