{"record":{"id":"482d7f690cdb728b","repo":"jamiepine/voicebox","slug":"generation-generation-id-not-found","errorCode":null,"errorMessage":"Generation {generation_id} not found","messagePattern":"Generation (.+?) not found","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/services/export_import.py","lineNumber":262,"sourceCode":"\ndef export_generation_to_zip(generation_id: str, db: Session) -> bytes:\n    \"\"\"\n    Export a generation to a ZIP archive.\n    \n    Args:\n        generation_id: Generation ID to export\n        db: Database session\n        \n    Returns:\n        ZIP file contents as bytes\n        \n    Raises:\n        ValueError: If generation not found\n    \"\"\"\n    # Get generation\n    generation = db.query(DBGeneration).filter_by(id=generation_id).first()\n    if not generation:\n        raise ValueError(f\"Generation {generation_id} not found\")\n    \n    # Get profile info\n    profile = db.query(DBVoiceProfile).filter_by(id=generation.profile_id).first()\n    if not profile:\n        raise ValueError(f\"Profile {generation.profile_id} not found\")\n    \n    # Get all versions for this generation\n    versions = (\n        db.query(DBGenerationVersion)\n        .filter_by(generation_id=generation_id)\n        .order_by(DBGenerationVersion.created_at)\n        .all()\n    )\n\n    # Create ZIP in memory\n    zip_buffer = io.BytesIO()\n    \n    with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zip_file:","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/jamiepine/voicebox/blob/51f49dea198384b4eb6087b72c17057c6eb1c1cd/backend/services/export_import.py#L244-L280","documentation":"Raised by export_generation_to_zip when db.query(DBGeneration).filter_by(id=generation_id).first() returns None (export_import.py:261-262). The generation row does not exist in the database — either it was deleted, the ID is wrong, or it belongs to a different database/tenant.","triggerScenarios":"API call GET /generations/{id}/export with an ID that is not in the generations table; the row was hard-deleted; the caller is hitting a different environment (dev vs prod) than where the generation was created; the ID has a typo or was URL-mangled.","commonSituations":"Stale bookmarked URL after the generation was deleted; copying an ID from a chatbot log that was already garbage-collected; multi-tenant system pointing at the wrong tenant's DB session.","solutions":["Confirm the ID exists: SELECT id, created_at FROM generations WHERE id = '<id>';.","If the row is missing, re-run the generation — the audio file alone cannot reconstruct the DB record.","Check that the request is hitting the same backend instance/environment where the generation was created.","Validate the ID format (UUID) before issuing the request to fail fast client-side."],"exampleFix":"# before: passing an unvalidated id straight through\ngen = export_generation_to_zip(possibly_bad_id, db)\n# after: existence check, 404-friendly error\ngen = db.query(DBGeneration).filter_by(id=generation_id).first()\nif not gen:\n    raise HTTPException(status_code=404, detail=\"Generation not found\")","handlingStrategy":"validation","validationCode":"def generation_exists(db, generation_id: str) -> bool:\n    return db.query(DBGeneration).filter_by(id=generation_id).first() is not None\n\n# in the route handler:\nif not generation_exists(db, generation_id):\n    raise HTTPException(404, f'Generation {generation_id} not found')\nzip_bytes = export_generation_to_zip(generation_id, db)","typeGuard":"null","tryCatchPattern":"try:\n    zip_bytes = export_generation_to_zip(generation_id, db)\nexcept ValueError as e:\n    if 'not found' in str(e):\n        raise HTTPException(404, str(e))\n    raise HTTPException(400, str(e))","preventionTips":["Validate UUID format and existence before calling the exporter.","Hide UI affordances for generations that have been deleted.","Confirm the environment (dev/prod) before reusing a generation ID."],"tags":["export","not-found","generation","database"],"backgroundTag":null,"analyzedSha":"51f49dea198384b4eb6087b72c17057c6eb1c1cd","analyzedAt":"2026-08-12T16:51:42.824Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}