--- 0.17.0:validate_inputs +++ 8010:validate_inputs @@ -1,6 +1,25 @@ -async def validate_inputs(prompt_id, prompt, item, validated): +async def validate_inputs(prompt_id, prompt, item, validated, visiting=None): + if visiting is None: + visiting = [] + unique_id = item if unique_id in validated: + return validated[unique_id] + + if unique_id in visiting: + cycle_path_nodes = visiting[visiting.index(unique_id):] + [unique_id] + cycle_nodes = list(dict.fromkeys(cycle_path_nodes)) + cycle_path = " -> ".join(f"{node_id} ({prompt[node_id]['class_type']})" for node_id in cycle_path_nodes) + for node_id in cycle_nodes: + validated[node_id] = (False, [{ + "type": "dependency_cycle", + "message": "Dependency cycle detected", + "details": cycle_path, + "extra_info": { + "node_id": node_id, + "cycle_nodes": cycle_nodes, + } + }], node_id) return validated[unique_id] inputs = prompt[unique_id]['inputs'] @@ -16,7 +35,17 @@ if issubclass(obj_class, _ComfyNodeInternal): obj_class: _io._ComfyNodeBaseInternal class_inputs = obj_class.INPUT_TYPES() - class_inputs, _, v3_data = _io.get_finalized_class_inputs(class_inputs, inputs) + try: + class_inputs, _, v3_data = _io.get_finalized_class_inputs(class_inputs, inputs) + except _io.DynamicInputError as ex: + errors.append({ + "type": "invalid_dynamic_input", + "message": "Invalid dynamic input", + "details": str(ex), + "extra_info": {"input_name": ex.input_name}, + }) + validated[unique_id] = (False, errors, unique_id) + return validated[unique_id] validate_function_name = "validate_inputs" validate_function = first_real_override(obj_class, validate_function_name) else: @@ -86,7 +115,11 @@ errors.append(error) continue try: - r = await validate_inputs(prompt_id, prompt, o_id, validated) + visiting.append(unique_id) + try: + r = await validate_inputs(prompt_id, prompt, o_id, validated, visiting) + finally: + visiting.pop() if r[0] is False: # `r` will be set in `validated[o_id]` already valid = False @@ -181,7 +214,12 @@ combo_options = extra_info.get("options", []) else: combo_options = input_type - if val not in combo_options: + is_multiselect = extra_info.get("multiselect", False) + if is_multiselect and isinstance(val, list): + invalid_vals = [v for v in val if v not in combo_options] + else: + invalid_vals = [val] if val not in combo_options else [] + if invalid_vals: input_config = info list_info = "" @@ -196,7 +234,7 @@ error = { "type": "value_not_in_list", "message": "Value not in list", - "details": f"{x}: '{val}' not in {list_info}", + "details": f"{x}: {', '.join(repr(v) for v in invalid_vals)} not in {list_info}", "extra_info": { "input_name": x, "input_config": input_config, @@ -208,37 +246,46 @@ if len(validate_function_inputs) > 0 or validate_has_kwargs: input_data_all, _, v3_data = get_input_data(inputs, obj_class, unique_id) + dynamic_paths = v3_data.get("dynamic_paths", {}) + if not validate_has_kwargs: + dynamic_paths = {key: path for key, path in dynamic_paths.items() if path.split(".")[0] in validate_function_inputs} + v3_data = v3_data | { + "dynamic_paths": dynamic_paths, + "list_paths": {path for path in v3_data.get("list_paths", set()) if path.split(".")[0] in validate_function_inputs}, + } input_filtered = {} for x in input_data_all: - if x in validate_function_inputs or validate_has_kwargs: + input_name = dynamic_paths[x].split(".")[0] if x in dynamic_paths else x + if input_name in validate_function_inputs or validate_has_kwargs: input_filtered[x] = input_data_all[x] if 'input_types' in validate_function_inputs: input_filtered['input_types'] = [received_types] ret = await _async_map_node_over_list(prompt_id, unique_id, obj_class, input_filtered, validate_function_name, v3_data=v3_data) ret = await resolve_map_node_over_list_results(ret) - for x in input_filtered: + for x in input_filtered or (None,): for i, r in enumerate(ret): if r is not True and not isinstance(r, ExecutionBlocker): - details = f"{x}" + details = x if x is not None else "" if r is not False: - details += f" - {str(r)}" + details = f"{x} - {r}" if x is not None else str(r) error = { "type": "custom_validation_failed", "message": "Custom validation failed for node", "details": details, - "extra_info": { - "input_name": x, - } + "extra_info": {"input_name": x} if x is not None else {}, } errors.append(error) continue - if len(errors) > 0 or valid is not True: - ret = (False, errors, unique_id) - else: - ret = (True, [], unique_id) + ret = validated.get(unique_id, (True, [], unique_id)) + # Recursive cycle detection may have already populated an error on us. Join it. + ret = ( + ret[0] and valid is True and not errors, + ret[1] + [error for error in errors if error not in ret[1]], + unique_id, + ) validated[unique_id] = ret - return ret+ return ret