{"record":{"id":"71f0edfbdab97afc","repo":"odysseus-dev/odysseus","slug":"name-cannot-be-empty","errorCode":null,"errorMessage":"Name cannot be empty","messagePattern":"Name cannot be empty","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"routes/gallery/gallery_routes.py","lineNumber":486,"sourceCode":"            except Exception:\n                db.rollback()\n                logger.exception(\"gallery_replace: DB commit failed\")\n                raise HTTPException(500, \"Image update failed\")\n            return {\"ok\": True, \"width\": img.width, \"height\": img.height}\n        finally:\n            db.close()\n\n    # ---- POST /api/gallery/{image_id}/rename ----\n    @router.post(\"/api/gallery/{image_id}/rename\")\n    async def gallery_rename(request: Request, image_id: str):\n        \"\"\"Rename a gallery photo. Stores the new name in the `prompt`\n        column (which serves as the user-facing label for uploaded\n        photos that have no AI prompt).\"\"\"\n        user = get_current_user(request)\n        data = await request.json()\n        new_name = (data.get(\"name\") or \"\").strip()\n        if not new_name:\n            raise HTTPException(400, \"Name cannot be empty\")\n        if len(new_name) > 500:\n            raise HTTPException(400, \"Name too long\")\n        db = SessionLocal()\n        try:\n            img = db.query(GalleryImage).filter(GalleryImage.id == image_id).first()\n            if not img:\n                raise HTTPException(404, \"Image not found\")\n            if not user or img.owner != user:\n                raise HTTPException(403, \"Not your image\")\n            img.prompt = new_name\n            db.commit()\n            return {\"ok\": True, \"name\": new_name}\n        finally:\n            db.close()\n\n    # ---- POST /api/gallery/{image_id}/rotate ----\n    @router.post(\"/api/gallery/{image_id}/rotate\")\n    async def gallery_rotate(request: Request, image_id: str):","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/routes/gallery/gallery_routes.py#L468-L504","documentation":"HTTP 400 raised by POST /api/gallery/{image_id}/rename when the submitted name is empty after stripping whitespace. The handler reads data['name'], applies (data.get('name') or '').strip() and rejects falsy results, so '', ' ', null, and a missing 'name' key all fail identically.","triggerScenarios":"Sending {\"name\": \"\"}, {\"name\": \"   \"}, {}, or {\"name\": null} in the JSON body of the rename request.","commonSituations":"UI rename dialog submitted without typing anything; double-submit clearing the input; frontend sending the wrong key (e.g. 'title') so .get() returns None.","solutions":["Require a non-blank name in the UI before enabling submit.","Send the field as exactly \"name\" with at least one non-whitespace character.","Trim client-side and skip the request entirely when empty."],"exampleFix":"// before\nawait post(`/api/gallery/${id}/rename`, {name: input.value});\n// after\nconst name = input.value.trim();\nif (!name) return showError('Enter a name');\nawait post(`/api/gallery/${id}/rename`, {name});","handlingStrategy":"validation","validationCode":"const name = (input?.value ?? '').trim();\nif (!name) return showError('Enter a name');\nawait post(`/api/gallery/${id}/rename`, {name});","typeGuard":"const isNonBlankName = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":null,"preventionTips":["Trim and require input client-side","Use the exact key 'name'","Disable submit while the field is blank"],"tags":["http","validation","gallery","rename"],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}