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

  1. Verify the exact image_name/key against SELECT image_name FROM images WHERE image_name LIKE '%partial%';
  2. If the file exists on disk but has no record, re-import/re-register the image so a DB row is created.
  3. If the image was deleted, treat the exception as expected (404-style) in the caller instead of retrying.
  4. 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

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


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/a6cccf0a87d98e1f. Report an issue: GitHub.