Skip to content

ChoiceNode exposes no input ports when combining real GradioNodes #44

@abidlabs

Description

@abidlabs

Description

When combining multiple real GradioNode instances using the | operator to create a ChoiceNode, the resulting node sometimes exposes no input ports, causing graph validation to fail.

Steps to Reproduce

  1. Create two or more GradioNode instances that connect to real HuggingFace Spaces
  2. Combine them with the | operator: choice = variant_a | variant_b
  3. Try to use the ChoiceNode in a graph where downstream nodes depend on its outputs

Expected Behavior

The ChoiceNode should expose the union of all variants' input ports (similar to how it handles output ports), allowing edges to be created and graph validation to pass.

Actual Behavior

The ChoiceNode._input_ports is empty, causing graph validation to fail when trying to connect inputs.

Current Workaround

Manually merge variant registries into the ChoiceNode:

def _merge_variant_registry_into_choice(choice):
    variants = getattr(choice, "_variants", None)
    if not variants:
        return choice

    if not hasattr(choice, "_input_ports"):
        choice._input_ports = []
    if not hasattr(choice, "_input_components"):
        choice._input_components = {}
    if not hasattr(choice, "_fixed_inputs"):
        choice._fixed_inputs = {}
    if not hasattr(choice, "_port_connections"):
        choice._port_connections = {}

    for v in variants:
        for p in getattr(v, "_input_ports", []):
            if p not in choice._input_ports:
                choice._input_ports.append(p)

        choice._input_components.update(getattr(v, "_input_components", {}))
        choice._fixed_inputs.update(getattr(v, "_fixed_inputs", {}))
        choice._port_connections.update(getattr(v, "_port_connections", {}))

    return choice

def safe_patch_choice(choice):
    variants = getattr(choice, "_variants", None)
    if not variants:
        return choice

    exposed_ports = getattr(choice, "_input_ports", None)
    if exposed_ports and len(exposed_ports) > 0:
        return choice

    print("[SAFE PATCH] ChoiceNode exposes no input ports → merging variant registries.")
    return _merge_variant_registry_into_choice(choice)

# Usage:
music_choice = variant_a | variant_b | variant_c
safe_patch_choice(music_choice)

Suggested Fix

Update ChoiceNode.__init__ to also compute the union of input ports, input components, and fixed inputs from all variants (similar to how _compute_union_output_ports works for outputs).

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions