{"record":{"id":"8d6053a79013fd26","repo":"invoke-ai/InvokeAI","slug":"model-not-found","errorCode":null,"errorMessage":"model not found","messagePattern":"model not found","errorType":"exception","errorClass":"UnknownModelException","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/model_records/model_records_sql.py","lineNumber":162,"sourceCode":"\n    def del_model(self, key: str) -> None:\n        \"\"\"\n        Delete a model.\n\n        :param key: Unique key for the model to be deleted\n\n        Can raise an UnknownModelException\n        \"\"\"\n        with self._db.transaction() as cursor:\n            cursor.execute(\n                \"\"\"--sql\n                DELETE FROM models\n                WHERE id=?;\n                \"\"\",\n                (key,),\n            )\n            if cursor.rowcount == 0:\n                raise UnknownModelException(\"model not found\")\n\n    def update_model(self, key: str, changes: ModelRecordChanges, allow_class_change: bool = False) -> AnyModelConfig:\n        with self._db.transaction() as cursor:\n            record = self.get_model(key)\n\n            if allow_class_change:\n                # The changes may cause the model config class to change. To handle this, we need to construct the new\n                # class from scratch rather than trying to modify the existing instance in place.\n                #\n                # 1. Convert the existing record to a dict\n                # 2. Apply the changes to the dict\n                # 3. Attempt to create a new model config from the updated dict\n\n                # 1. Convert the existing record to a dict\n                record_as_dict = record.model_dump()\n\n                # 2. Apply the changes to the dict\n                for field_name in changes.model_fields_set:","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/model_records/model_records_sql.py#L144-L180","documentation":"del_model deletes the row with the given key from the models table; if the DELETE affects zero rows it raises UnknownModelException('model not found'). It guarantees delete operations fail loudly rather than silently no-op on a stale key.","triggerScenarios":"Calling del_model(key) with a key that was already deleted, never existed, or from a different database; racing concurrent deletes (two requests deleting the same model); using a key from a stale cached config.","commonSituations":"Double-clicking delete in the UI issuing two requests; automation scripts deleting models whose keys were fetched earlier in the run; pointing at a different DB file than expected (wrong InvokeAI root).","solutions":["Check existence with get_model/search before deleting, or catch UnknownModelException and treat it as already-deleted success (idempotent delete).","Refresh the model list to obtain current keys.","Verify you are operating on the intended InvokeAI database/root directory."],"exampleFix":"# before\nrecords.del_model(key)  # UnknownModelException on second run\n# after\ntry:\n    records.del_model(key)\nexcept UnknownModelException:\n    pass  # already deleted; idempotent","handlingStrategy":"try-catch","validationCode":"def safe_del(records, key) -> bool:\n    try:\n        records.get_model(key)\n    except UnknownModelException:\n        return False\n    records.del_model(key)\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    records.del_model(key)\nexcept UnknownModelException:\n    log.info('Model %s already deleted; treating as success', key)","preventionTips":["Make deletes idempotent by ignoring UnknownModelException where appropriate","Fetch keys immediately before deleting; do not cache across long runs","Serialize delete operations to avoid racing double-deletes","Confirm the InvokeAI root/DB you are operating on matches the UI"],"tags":["model-not-found","delete","idempotency","sqlite"],"backgroundTag":"model-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}