{"record":{"id":"a6cccf0a87d98e1f","repo":"invoke-ai/InvokeAI","slug":"imagerecordnotfoundexception","errorCode":null,"errorMessage":"ImageRecordNotFoundException","messagePattern":"ImageRecordNotFoundException","errorType":"exception","errorClass":"ImageRecordNotFoundException","httpStatus":404,"severity":"error","filePath":"invokeai/app/services/image_records/image_records_sqlite.py","lineNumber":50,"sourceCode":"        # This used to be caught and re-raised as not-found, which made the exception mean\n        # \"the row is absent, OR the database is locked/corrupt/unreadable\". Callers that\n        # treat not-found as a benign outcome — the concurrent-deletion skips in the images\n        # and board_images batch routes — would then swallow a disk I/O error as a routine\n        # race and answer 200 with the name in no result list at all. Let the storage error\n        # propagate: ImageService logs it and the route reports it as a real failure.\n        with self._db.transaction() as cursor:\n            cursor.execute(\n                f\"\"\"--sql\n                SELECT {IMAGE_DTO_COLS} FROM images\n                WHERE image_name = ?;\n                \"\"\",\n                (image_name,),\n            )\n\n            result = cast(Optional[sqlite3.Row], cursor.fetchone())\n\n        if not result:\n            raise ImageRecordNotFoundException\n\n        return deserialize_image_record(dict(result))\n\n    def get_user_id(self, image_name: str) -> Optional[str]:\n        with self._db.transaction() as cursor:\n            cursor.execute(\n                \"\"\"--sql\n                SELECT user_id FROM images\n                WHERE image_name = ?;\n                \"\"\",\n                (image_name,),\n            )\n            result = cast(Optional[sqlite3.Row], cursor.fetchone())\n            if not result:\n                return None\n            return cast(Optional[str], dict(result).get(\"user_id\"))\n\n    def exists(self, image_name: str) -> bool:","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/image_records/image_records_sqlite.py#L32-L68","documentation":"SqliteImageRecordStorage.get fetches an image row by image_name and raises ImageRecordNotFoundException when no row matches. It is the standard 'image not in the gallery database' signal used throughout InvokeAI's image services.","triggerScenarios":"Calling get, get_user_id, or code paths that depend on it with an image_name absent from the images table — deleted images, typos in the name (including missing subfolder prefix), querying the wrong DB, or an image file present on disk whose DB record was removed.","commonSituations":"Stale URLs/IDs in the UI after deleting images; referencing images by filename only when the record key includes the subfolder; restored DB older than the images folder; board/album references to purged images.","solutions":["Verify the exact image_name/key against SELECT image_name FROM images WHERE image_name LIKE '%partial%';","If the file exists on disk but has no record, re-import/re-register the image so a DB row is created.","If the image was deleted, treat the exception as expected (404-style) in the caller instead of retrying.","Confirm you're connected to the correct invokeai.db for the running instance."],"exampleFix":"// before\nrecord = image_records.get(\"abc.png\")  # raises if absent\n// after\ntry:\n    record = image_records.get(\"abc.png\")\nexcept ImageRecordNotFoundException:\n    record = None  # image not in gallery; handle gracefully","handlingStrategy":"try-catch","validationCode":"import sqlite3\ndef image_record_exists(db_path: str, image_name: str) -> bool:\n    con = sqlite3.connect(db_path)\n    return con.execute(\"SELECT 1 FROM images WHERE image_name=?\", (image_name,)).fetchone() is not None","typeGuard":"def record_found(row) -> bool:\n    return row is not None","tryCatchPattern":"from invokeai.app.services.image_records.image_records_common import ImageRecordNotFoundException\ntry:\n    record = image_records.get(image_name)\nexcept ImageRecordNotFoundException:\n    record = None  # treat as 404: image absent from gallery DB","preventionTips":["Use exact image_name keys as returned by list/search APIs, not raw filenames","Refresh stale gallery URLs/IDs after deleting images","Check for the record before dependent calls (metadata, URLs)","Ensure DB and images folder are restored from the same backup point"],"tags":["database","sqlite","not-found","image-records"],"backgroundTag":"record-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}