{"record":{"id":"c5da4a56d4724900","repo":"invoke-ai/InvokeAI","slug":"model-config-dict-type-field-must-be-a-string-or","errorCode":null,"errorMessage":"Model config dict 'type' field must be a string or Enum","messagePattern":"Model config dict 'type' field must be a string or Enum","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/base.py","lineNumber":170,"sourceCode":"    @staticmethod\n    def get_model_discriminator_value(v: Any) -> str:\n        \"\"\"Computes the discriminator value for a model config discriminated union.\"\"\"\n        # This is called by pydantic during deserialization and serialization to determine which model the data\n        # represents. It can get either a dict (during deserialization) or an instance of a Config_Base subclass\n        # (during serialization).\n        #\n        # See: https://docs.pydantic.dev/latest/concepts/unions/#discriminated-unions-with-callable-discriminator\n        if isinstance(v, Config_Base):\n            # We have an instance of a ModelConfigBase subclass - use its tag directly.\n            return v.get_tag().tag\n        if isinstance(v, dict):\n            # We have a dict - attempt to compute a tag from its fields.\n            tag_strings: list[str] = []\n            if type_ := v.get(\"type\"):\n                if isinstance(type_, Enum):\n                    type_ = str(type_.value)\n                elif not isinstance(type_, str):\n                    raise ValueError(\"Model config dict 'type' field must be a string or Enum\")\n                tag_strings.append(type_)\n\n            if format_ := v.get(\"format\"):\n                if isinstance(format_, Enum):\n                    format_ = str(format_.value)\n                elif not isinstance(format_, str):\n                    raise ValueError(\"Model config dict 'format' field must be a string or Enum\")\n                tag_strings.append(format_)\n\n            if base_ := v.get(\"base\"):\n                if isinstance(base_, Enum):\n                    base_ = str(base_.value)\n                elif not isinstance(base_, str):\n                    raise ValueError(\"Model config dict 'base' field must be a string or Enum\")\n                tag_strings.append(base_)\n\n            # Special case: CLIP Embed models also need the variant to distinguish them.\n            if (","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/base.py#L152-L188","documentation":"get_model_discriminator_value builds a pydantic discriminated-union tag from a config dict's 'type' field, which must be a string or an Enum. Any other type raises ValueError so pydantic can route to the correct model config class.","triggerScenarios":"Instantiating a model config (ModelConfigBase or subclass) from a dict whose 'type' is an int, ModelType-typed wrapper, bytes, or other non-str/non-Enum value.","commonSituations":"Loading configs from JSON where enums were serialized as integers; hand-writing a config dict with the wrong type; passing a ModelType instance that is not an Enum (e.g. a plain dataclass).","solutions":["Pass the enum value string: {'type': ModelType.Main.value} or simply {'type': 'main'}.","Pass the Enum member itself (isinstance Enum is accepted and converted).","Fix serialization upstream so enums are dumped with use_enum_values or as strings, not ints/bytes."],"exampleFix":"// before\n{'type': 3, 'format': 'diffusers', 'base': 'sd-1'}\n// after\n{'type': ModelType.Main.value, 'format': 'diffusers', 'base': BaseModelType.StableDiffusion1.value}","handlingStrategy":"validation","validationCode":"from enum import Enum\n\ndef valid_discriminator_field(v) -> bool:\n    return isinstance(v, (str, Enum))","typeGuard":"def is_str_or_enum(v: object) -> TypeGuard[str | Enum]:\n    return isinstance(v, (str, Enum))","tryCatchPattern":"try:\n    config = AnyModelConfig(**cfg)\nexcept ValueError as e:\n    if \"'type' field must be a string or Enum\" in str(e):\n        cfg['type'] = cfg['type'].value if isinstance(cfg['type'], Enum) else str(cfg['type'])\n        config = AnyModelConfig(**cfg)\n    else:\n        raise","preventionTips":["Serialize model configs with model_dump(mode='json') / use_enum_values so enums become strings.","Never pass raw enum integer codes from external tools into config dicts.","Write a small normalizer that maps every discriminator field through .value before instantiation."],"tags":["invokeai","pydantic","discriminator","type-mismatch"],"backgroundTag":"discriminator-validation-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}