frontend will no longer namespace dynamic inputs widgets so reflect that in code, refactor build_nested_inputs

This commit is contained in:
Jedrzej Kosinski 2025-11-18 01:41:25 -08:00
parent 122c9d5362
commit 47128ee279
2 changed files with 10 additions and 8 deletions

View File

@ -888,8 +888,7 @@ def add_dynamic_id_mapping(d: dict[str], inputs: list[Input], curr_prefix: str,
dynamic[self.id] = f"{curr_prefix}{self.id}"
for i in inputs:
if not isinstance(i, DynamicInput):
# frontend keys should include the prefixes
dynamic[f"{curr_prefix}{i.id}"] = f"{curr_prefix}{i.id}"
dynamic[f"{i.id}"] = f"{curr_prefix}{i.id}"
@comfytype(io_type="COMFY_DYNAMICCOMBO_V3")
class DynamicCombo(ComfyTypeI):
@ -1279,9 +1278,9 @@ def add_to_input_dict_v1(d: dict[str], inputs: list[Input], live_inputs: dict[st
if live_inputs is not None:
i.add_to_dict_live_inputs(d, live_inputs, curr_prefix)
else:
add_to_dict_v1(i, d, curr_prefix=curr_prefix)
add_to_dict_v1(i, d)
def add_to_dict_v1(i: Input, d: dict, dynamic_dict: dict=None, curr_prefix=''):
def add_to_dict_v1(i: Input, d: dict, dynamic_dict: dict=None):
key = "optional" if i.optional else "required"
as_dict = i.as_dict()
# for v1, we don't want to include the optional key
@ -1290,12 +1289,15 @@ def add_to_dict_v1(i: Input, d: dict, dynamic_dict: dict=None, curr_prefix=''):
value = (i.get_io_type(), as_dict)
else:
value = (i.get_io_type(), as_dict, dynamic_dict)
d.setdefault(key, {})[f"{curr_prefix}{i.id}"] = value
d.setdefault(key, {})[i.id] = value
def add_to_dict_v3(io: Input | Output, d: dict):
d[io.id] = (io.get_io_type(), io.as_dict())
def build_nested_inputs(values: dict[str], paths: dict[str]):
def build_nested_inputs(values: dict[str], v3_data: V3Data):
paths = v3_data.get("dynamic_data", None)
if paths is None:
return values
# NOTE: This was initially AI generated
# Tries to account for arrays as well, will likely be changed once that's in
values = values.copy()

View File

@ -269,8 +269,8 @@ async def _async_map_node_over_list(prompt_id, unique_id, obj, input_data_all, f
class_clone = type_obj.PREPARE_CLASS_CLONE(v3_data)
f = make_locked_method_func(type_obj, func, class_clone)
# in case of dynamic inputs, restructure inputs to expected nested dict
if v3_data is not None and v3_data["dynamic_data"] is not None:
inputs = _io.build_nested_inputs(inputs, v3_data["dynamic_data"])
if v3_data is not None:
inputs = _io.build_nested_inputs(inputs, v3_data)
# V1
else:
f = getattr(obj, func)