{"record":{"id":"ebd27e6dfa792e3e","repo":"invoke-ai/InvokeAI","slug":"invalid-override-for-field-field-name-e","errorCode":null,"errorMessage":"invalid override for field '{field_name}': {e}","messagePattern":"invalid override for field '(.+?)': (.+?)","errorType":"validation","errorClass":"NotAMatchError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_manager/configs/identification_utils.py","lineNumber":154,"sourceCode":"    the override fields contain \"base\": BaseModelType.Flux, this function will raise NotAMatch.\n\n    Internally, this function extracts the pydantic schema for each individual override field from the candidate config\n    class and validates the override value against that schema. Post-instantiation validators are not run.\n\n    Args:\n        candidate_config_class: The config class that is being tested.\n        override_fields: The override fields provided by the user.\n\n    Raises:\n        NotAMatch if any override field is invalid for the config class.\n    \"\"\"\n    for field_name, override_value in override_fields.items():\n        if field_name not in candidate_config_class.model_fields:\n            raise NotAMatchError(f\"unknown override field: {field_name}\")\n        try:\n            PydanticFieldValidator.validate_field(candidate_config_class, field_name, override_value)\n        except ValidationError as e:\n            raise NotAMatchError(f\"invalid override for field '{field_name}': {e}\") from e\n\n\ndef raise_if_not_file(mod: ModelOnDisk) -> None:\n    \"\"\"Raise NotAMatch if the model path is not a file.\"\"\"\n    if not mod.path.is_file():\n        raise NotAMatchError(\"model path is not a file\")\n\n\ndef raise_if_not_dir(mod: ModelOnDisk) -> None:\n    \"\"\"Raise NotAMatch if the model path is not a directory.\"\"\"\n    if not mod.path.is_dir():\n        raise NotAMatchError(\"model path is not a directory\")\n\n\ndef state_dict_has_any_keys_exact(state_dict: dict[str | int, Any], keys: str | set[str]) -> bool:\n    \"\"\"Returns true if the state dict has any of the specified keys.\"\"\"\n    _keys = {keys} if isinstance(keys, str) else keys\n    return any(key in state_dict for key in _keys)","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_manager/configs/identification_utils.py#L136-L172","documentation":"After confirming the override field exists, raise_for_override_fields runs PydanticFieldValidator.validate_field to check the value's type/allowed values against the config class. A pydantic ValidationError is wrapped (chained) as NotAMatchError with the field name and original validation message. This keeps override failures within InvokeAI's uniform NotAMatch probing flow.","triggerScenarios":"Calling from_model_on_disk with override_fields whose value violates the field's pydantic type or Literal constraints (e.g. base=\"sd-1\" instead of BaseModelType.StableDiffusion1, or an out-of-enum model_format).","commonSituations":"Passing raw strings where enums/Literals are expected; wrong variant/format names; numeric types where strings are required; overrides constructed from user input without pre-validation.","solutions":["Read the chained pydantic message to see which field value failed and why.","Use the exact enum/Literal values the config class defines (e.g. BaseModelType.StableDiffusion1, ModelType.IpAdapter, ModelFormat.Diffusers).","Pre-validate overrides with the config class's pydantic model (e.g. CandidateConfig.model_validate(overrides)) before calling.","Fix client/API payloads that send wrong types (strings vs ints)."],"exampleFix":"// before\noverride_fields = {\"base\": \"sd-1\"}\n// after\nfrom invokeai.backend.model_manager import BaseModelType\noverride_fields = {\"base\": BaseModelType.StableDiffusion1}","handlingStrategy":"validation","validationCode":"from pydantic import ValidationError\ntry:\n    candidate_config_class.model_validate({**defaults, **override_fields})\nexcept ValidationError as e:\n    raise ValueError(f\"invalid overrides: {e}\") from e","typeGuard":"def overrides_are_valid(cfg_cls, overrides: dict) -> bool:\n    from pydantic import ValidationError\n    try:\n        cfg_cls.model_validate(dict(overrides))\n        return True\n    except ValidationError:\n        return False","tryCatchPattern":"try:\n    record = from_model_on_disk(mod, config_class, override_fields=overrides)\nexcept NotAMatchError as e:\n    if \"invalid override\" in str(e):\n        logger.error(\"override value rejected: %s\", e)\n        raise HTTPException(422, str(e)) from e","preventionTips":["Pass enum members (BaseModelType, ModelType, ModelFormat) rather than raw strings","Validate user-supplied overrides with the pydantic config class first","Log the chained pydantic message to pinpoint offending values"],"tags":["validation","pydantic","invokeai"],"backgroundTag":"field-validation-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}