invoke-ai/InvokeAI · error · ImageRecordNotFoundException
ImageRecordNotFoundException
Error message
ImageRecordNotFoundException
What it means
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.
Source
Thrown at invokeai/app/services/image_records/image_records_sqlite.py:50
# This used to be caught and re-raised as not-found, which made the exception mean
# "the row is absent, OR the database is locked/corrupt/unreadable". Callers that
# treat not-found as a benign outcome — the concurrent-deletion skips in the images
# and board_images batch routes — would then swallow a disk I/O error as a routine
# race and answer 200 with the name in no result list at all. Let the storage error
# propagate: ImageService logs it and the route reports it as a real failure.
with self._db.transaction() as cursor:
cursor.execute(
f"""--sql
SELECT {IMAGE_DTO_COLS} FROM images
WHERE image_name = ?;
""",
(image_name,),
)
result = cast(Optional[sqlite3.Row], cursor.fetchone())
if not result:
raise ImageRecordNotFoundException
return deserialize_image_record(dict(result))
def get_user_id(self, image_name: str) -> Optional[str]:
with self._db.transaction() as cursor:
cursor.execute(
"""--sql
SELECT user_id FROM images
WHERE image_name = ?;
""",
(image_name,),
)
result = cast(Optional[sqlite3.Row], cursor.fetchone())
if not result:
return None
return cast(Optional[str], dict(result).get("user_id"))
def exists(self, image_name: str) -> bool:View on GitHub (pinned to 0b6a024f2f)
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.
Example fix
// before
record = image_records.get("abc.png") # raises if absent
// after
try:
record = image_records.get("abc.png")
except ImageRecordNotFoundException:
record = None # image not in gallery; handle gracefully Defensive patterns
Strategy: try-catch
Validate before calling
import sqlite3
def image_record_exists(db_path: str, image_name: str) -> bool:
con = sqlite3.connect(db_path)
return con.execute("SELECT 1 FROM images WHERE image_name=?", (image_name,)).fetchone() is not None Type guard
def record_found(row) -> bool:
return row is not None Try / catch
from invokeai.app.services.image_records.image_records_common import ImageRecordNotFoundException
try:
record = image_records.get(image_name)
except ImageRecordNotFoundException:
record = None # treat as 404: image absent from gallery DB Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Workflow with id {workflow_id} not found
- Image move job {job_id} failed commit validation
- Image move job not found: {job_id}
- No queue item with id {item_id}
- Database is at version {version}, expected {expected}
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/a6cccf0a87d98e1f.
Report an issue: GitHub.