{"record":{"id":"9187f48dfa36fe19","repo":"invoke-ai/InvokeAI","slug":"no-model-config-class-found-for-type-target-type","errorCode":null,"errorMessage":"No model config class found for type={target_type!r}","messagePattern":"No model config class found for type=(.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/model_records/model_records_sql.py","lineNumber":86,"sourceCode":"def _construct_config_for_type(fields: dict, target_type: ModelType) -> AnyModelConfig:\n    \"\"\"Try every config class whose `type` default matches `target_type` and return the first that validates.\n\n    Used when changing a model's type via the update endpoint: the existing record's `format`/`variant`\n    fields belong to the old class and may not have a discriminator match in the new type space, so we\n    fall back to constructing each candidate class directly with whatever fields it accepts.\n    \"\"\"\n    last_error: Exception | None = None\n    for candidate_class in Config_Base.CONFIG_CLASSES:\n        type_field = candidate_class.model_fields.get(\"type\")\n        if type_field is None or type_field.default != target_type:\n            continue\n        try:\n            return candidate_class(**fields)  # type: ignore[return-value]\n        except ValidationError as e:\n            last_error = e\n    if last_error is not None:\n        raise last_error\n    raise ValidationError.from_exception_data(\n        f\"No model config class found for type={target_type!r}\",\n        line_errors=[],\n    )\n\n\nclass ModelRecordServiceSQL(ModelRecordServiceBase):\n    \"\"\"Implementation of the ModelConfigStore ABC using a SQL database.\"\"\"\n\n    def __init__(self, db: SqliteDatabase, logger: logging.Logger):\n        \"\"\"\n        Initialize a new object from preexisting sqlite3 connection and threading lock objects.\n\n        :param db: Sqlite connection object\n        \"\"\"\n        super().__init__()\n        self._db = db\n        self._logger = logger\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/model_records/model_records_sql.py#L68-L104","documentation":"_construct_config_for_type tries candidate pydantic config classes for a given model record type; if none exists for target_type and no candidate produced a ValidationError, it synthesizes a ValidationError stating no config class was found. This surfaces through update_model when a model record has an unknown/unregistered model type.","triggerScenarios":"Updating a model record (update_model) whose stored type value is not one of the known model types (e.g. a corrupted DB row, a type from a newer/older InvokeAI version, or hand-edited database).","commonSituations":"Database written by a different InvokeAI version where the type enum changed; manual SQL edits introducing a bad type string; plugin/custom model types not registered in the running process.","solutions":["Check the type field of the offending model row and correct it to a valid model type.","Update InvokeAI so the running code recognizes the record's type (version mismatch).","Delete the invalid record via del_model and re-add the model.","Restore the models DB from a backup or re-scan models from disk."],"exampleFix":"# before\n# models table row: {\"type\": \"main_v3_experimental\", ...}\n# after\n# correct the row to a known type\n# {\"type\": \"main\", ...}  (or upgrade InvokeAI to a version that knows the type)","handlingStrategy":"try-catch","validationCode":"KNOWN_TYPES = {'main','vae','controlnet','embedding','lora','t2i_adapter','textual_inversion','ip_adapter','clip_vision','sig_lora','unknown'}\nassert record.get('type') in KNOWN_TYPES, f\"Unknown model type: {record.get('type')!r}\"","typeGuard":"def has_known_type(rec: dict) -> bool:\n    return rec.get('type') in {'main','vae','controlnet','embedding','lora','t2i_adapter','ip_adapter','clip_vision','sig_lora'}","tryCatchPattern":"try:\n    records.update_model(key, changes)\nexcept ValidationError as e:\n    if 'No model config class found' in str(e):\n        log.error('Record %s has an unrecognized type; skipping or re-adding', key)\n        records.del_model(key)\n    else:\n        raise","preventionTips":["Keep InvokeAI versions consistent with the database you operate on","Never hand-edit the models DB","Re-add models with unrecognized types from source files"],"tags":["model-config","schema-mismatch","unknown-type","validation"],"backgroundTag":"unknown-model-type","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}