From 9d5ae2f68c2ee4404dbd16e2440f73e069dd3441 Mon Sep 17 00:00:00 2001 From: jaeone94 <89377375+jaeone94@users.noreply.github.com> Date: Fri, 11 Sep 2026 14:16:58 +0900 Subject: [PATCH 1/7] Add DynamicGroup widget input Validate submitted row counts independently of template field requirements, preserve sparse positions within a fixed index limit, and keep empty groups as lists in lazy callbacks. Adapted from https://github.com/Comfy-Org/ComfyUI/pull/14507. Co-authored-by: Talmaj Marinc --- comfy_api/latest/_io.py | 116 ++++++++++++- .../comfy_api_test/io_dynamic_group_test.py | 153 ++++++++++++++++++ 2 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 tests-unit/comfy_api_test/io_dynamic_group_test.py diff --git a/comfy_api/latest/_io.py b/comfy_api/latest/_io.py index 4c062d8aabc..c1b64ff9deb 100644 --- a/comfy_api/latest/_io.py +++ b/comfy_api/latest/_io.py @@ -1316,6 +1316,100 @@ def _expand_schema_for_dynamic(out_dict: dict[str, Any], live_inputs: dict[str, out_dict[input_type][finalized_id] = value out_dict["dynamic_paths"][finalized_id] = finalize_prefix(curr_prefix, curr_prefix[-1]) +@comfytype(io_type="COMFY_DYNAMICGROUP_V3") +class DynamicGroup(ComfyTypeI): + """Repeat a widget template and pass its values to execute as a list of row dicts. + + min/max count submitted rows, independently of the template's required fields. + Missing indices are preserved as rows whose fields are None, so the resulting + list can be longer than max. Its length is limited to 100. Use min=0 to allow + an empty group, including when the group input is optional. + """ + + Type = list[dict[str, Any]] + _MaxRows = 100 + + class Input(DynamicInput): + def __init__(self, id: str, template: list[WidgetInput], min: int=0, max: int=50, + display_name: str=None, optional: bool=False, tooltip: str=None, + lazy: bool=None, extra_dict=None, group_name: str="Group"): + super().__init__(id, display_name, optional, tooltip, lazy, extra_dict) + assert len(template) > 0, "DynamicGroup template must have at least one field." + for t in template: + assert isinstance(t, WidgetInput), f"DynamicGroup template field '{t.id}' must be a WidgetInput." + assert not isinstance(t, DynamicInput), "Nesting dynamic inputs inside DynamicGroup is not supported." + assert not t.force_input, f"DynamicGroup template field '{t.id}' must not use force_input." + assert "." not in t.id, f"DynamicGroup template field id must not contain '.'. Got: '{t.id}'" + field_ids = [t.id for t in template] + assert len(field_ids) == len(set(field_ids)), "DynamicGroup template field ids must be unique within a row." + assert "." not in id, f"DynamicGroup id must not contain '.'. Got: '{id}'" + assert min >= 0, "DynamicGroup min must be >= 0." + assert max >= 1, "DynamicGroup max must be >= 1." + assert max <= DynamicGroup._MaxRows, f"DynamicGroup max must be <= {DynamicGroup._MaxRows}." + assert min <= max, "DynamicGroup min must be <= max." + self.template = template + self.min = min + self.max = max + self.group_name = group_name + + def get_all(self) -> list[Input]: + return [self] + list(self.template) + + def as_dict(self): + return super().as_dict() | prune_dict({ + "template": create_input_dict_v1(self.template), + "min": self.min, + "max": self.max, + "group_name": self.group_name, + }) + + def validate(self): + for t in self.template: + t.validate() + + @staticmethod + def _expand_schema_for_dynamic(out_dict: dict[str, Any], live_inputs: dict[str, Any], value: tuple[str, dict[str, Any]], input_type: str, curr_prefix: list[str] | None): + info = value[1] + min_rows = info.get("min", 0) + max_rows = info.get("max", DynamicGroup._MaxRows) + template = info.get("template", {}) + field_specs = { + field_id: (field_value, category) + for category in ("required", "optional") + for field_id, field_value in template.get(category, {}).items() + } + finalized_prefix = finalize_prefix(curr_prefix) + prefix = finalized_prefix + "." + present_rows = set() + for key in live_inputs: + if not key.startswith(prefix): + continue + index, separator, field_id = key[len(prefix):].partition(".") + if (not separator or not index.isascii() or not index.isdecimal() + or (len(index) > 1 and index.startswith("0")) or field_id not in field_specs): + raise ValueError(f"Invalid DynamicGroup input key '{key}'; expected '{finalized_prefix}..