{"record":{"id":"6ec8903766f702b2","repo":"invoke-ai/InvokeAI","slug":"image-move-job-not-found-job-id","errorCode":null,"errorMessage":"Image move job not found: {job_id}","messagePattern":"Image move job not found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":404,"severity":"error","filePath":"invokeai/app/services/image_moves/image_moves_default.py","lineNumber":710,"sourceCode":"        with self._db.transaction() as cursor:\n            cursor.execute(\n                \"UPDATE image_subfolder_move_jobs SET state = 'error', error_message = ? WHERE id = ?;\",\n                (message, job_id),\n            )\n            cursor.execute(\n                \"UPDATE image_subfolder_move_items SET state = 'error', error_message = ? WHERE job_id = ?;\",\n                (message, job_id),\n            )\n\n    def get_job(self, job_id: int) -> ImageMoveJob:\n        with self._db.transaction() as cursor:\n            cursor.execute(\n                \"SELECT id, state, error_message FROM image_subfolder_move_jobs WHERE id = ?;\",\n                (job_id,),\n            )\n            row = cursor.fetchone()\n        if row is None:\n            raise ValueError(f\"Image move job not found: {job_id}\")\n        return ImageMoveJob(\n            id=cast(int, row[\"id\"]), state=cast(MoveJobState, row[\"state\"]), error_message=row[\"error_message\"]\n        )\n\n    def get_latest_job(self) -> ImageMoveJob | None:\n        with self._db.transaction() as cursor:\n            cursor.execute(\n                \"\"\"--sql\n                SELECT id, state, error_message\n                FROM image_subfolder_move_jobs\n                ORDER BY id DESC\n                LIMIT 1;\n                \"\"\"\n            )\n            row = cursor.fetchone()\n        if row is None:\n            return None\n        return ImageMoveJob(","sourceCodeStart":692,"sourceCodeEnd":728,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/image_moves/image_moves_default.py#L692-L728","documentation":"get_job looks up an image move job by id in image_subfolder_move_jobs; if no row matches, it raises ValueError('Image move job not found: {job_id}'). It signals the caller passed a job id that does not exist (or no longer exists) in the database.","triggerScenarios":"Calling get_job(job_id) with an id from another/older database, an id for a job that was deleted, a fabricated id (e.g. 0 or 1 on a fresh DB), or using a job id after the DB file was reset/recreated.","commonSituations":"Storing a job id across app reinstalls or DB migrations; querying a test DB while the id came from a dev DB; calling recovery APIs with an id hardcoded from a tutorial.","solutions":["Call get_latest_job() to see whether any move job exists and use its id.","Verify you are querying the same invokeai.db the job was created against (check the configured database path).","List existing jobs with SELECT id, state FROM image_subfolder_move_jobs; and pick a valid id.","Handle the ValueError in caller code when the job may legitimately not exist (e.g. after DB reset)."],"exampleFix":"// before\njob = move_service.get_job(42)  # ValueError if absent\n// after\njob = move_service.get_latest_job()\nif job is None:\n    print(\"no move jobs recorded\")\nelse:\n    job = move_service.get_job(job.id)","handlingStrategy":"try-catch","validationCode":"def job_exists(db_path: str, job_id: int) -> bool:\n    import sqlite3\n    con = sqlite3.connect(db_path)\n    row = con.execute(\"SELECT 1 FROM image_subfolder_move_jobs WHERE id=?\", (job_id,)).fetchone()\n    return row is not None","typeGuard":"def is_valid_job(job) -> bool:\n    return job is not None and isinstance(getattr(job, 'id', None), int)","tryCatchPattern":"try:\n    job = service.get_job(job_id)\nexcept ValueError as e:\n    if \"Image move job not found\" in str(e):\n        job = service.get_latest_job()  # fall back to most recent","preventionTips":["Use get_latest_job() instead of guessing job ids","Persist job ids only alongside the same DB instance they were created in","List jobs via SQL before querying a specific id","Expect not-found after DB resets/reinstalls"],"tags":["database","image-move","not-found","valueerror"],"backgroundTag":"record-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}