Comfy-Org/ComfyUI · error · ValueError

Cannot convert type {type(value).__name__} to {cls.__name__}

Error message

Cannot convert type {type(value).__name__} to {cls.__name__} enum. Expected string, None, or {cls.__name__} instance.

What it means

Raised by StringConvertibleEnum when the value passed is neither an instance of the enum, None, nor a str — for example an int, bool, or list. The enum coercion only supports string, None, and enum instances; anything else has no defined conversion.

Source

Thrown at comfy/ldm/lightricks/vae/causal_audio_autoencoder.py:69

                # Handle members with None values
                if member.value is None:
                    if value_lower == "none":
                        return member
                # Handle members with string values
                elif isinstance(member.value, str) and member.value.lower() == value_lower:
                    return member

            # Build helpful error message with valid values
            valid_values = []
            for member in cls:
                if member.value is None:
                    valid_values.append("none")
                elif isinstance(member.value, str):
                    valid_values.append(member.value)

            raise ValueError(f"Invalid {cls.__name__} string: '{value}'. " f"Valid values are: {valid_values}")

        raise ValueError(
            f"Cannot convert type {type(value).__name__} to {cls.__name__} enum. "
            f"Expected string, None, or {cls.__name__} instance."
        )


class AttentionType(StringConvertibleEnum):
    """Enum for specifying the attention mechanism type."""

    VANILLA = "vanilla"
    LINEAR = "linear"
    NONE = "none"


class CausalityAxis(StringConvertibleEnum):
    """Enum for specifying the causality axis in causal convolutions."""

    NONE = None
    WIDTH = "width"

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Convert the value to its string name before passing (str(value) if it names a member)
  2. Look up the enum member by whatever mapping your config uses and pass that member
  3. If integer codes are required upstream, map them explicitly: {0: AttentionType.VANILLA, ...}[code]

Example fix

# before
attn_type = 0  # from an int-indexed config
make_attention(in_channels, attn_type=attn_type)

# after
INT_TO_ATTN = {0: AttentionType.VANILLA, 1: AttentionType.LINEAR, 2: AttentionType.NONE}
make_attention(in_channels, attn_type=INT_TO_ATTN[attn_type])
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(attn_type, (str, AttentionType)) and attn_type is not None:
    raise TypeError(f"expected str, None, or AttentionType, got {type(attn_type).__name__}")

Type guard

def is_enum_convertible(cls, v) -> bool:
    return isinstance(v, (cls, str)) or v is None

Prevention

When it happens

Trigger: Passing a non-string scalar to an enum-typed parameter, e.g. CausalityAxis(0), AttentionType(1), or AttentionType(True); often happens when configs use integer codes from a different schema.

Common situations: Configs migrated from integer-indexed enums in other codebases; programmatic config generation that emits ints; booleans intended as flags passed to enum fields.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/20e6d9d4a461fe24. Report an issue: GitHub.