{"record":{"id":"be9063a4a6b92585","repo":"odysseus-dev/odysseus","slug":"name-too-long","errorCode":null,"errorMessage":"Name too long","messagePattern":"Name too long","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"warning","filePath":"routes/gallery/gallery_routes.py","lineNumber":488,"sourceCode":"                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):\n        \"\"\"Rotate an image by ±90° or 180°. Updates the file on disk and the\n        width/height in the DB. Body: {angle: 90 | -90 | 180}.\"\"\"","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/routes/gallery/gallery_routes.py#L470-L506","documentation":"HTTP 400 raised by POST /api/gallery/{image_id}/rename when the stripped name exceeds 500 characters. The limit guards the prompt column that stores the user-facing label for uploaded photos; anything longer is rejected before any DB access.","triggerScenarios":"Sending a JSON body whose \"name\" string is longer than 500 characters after trimming.","commonSituations":"Pasting long text or a whole file path into the rename field; scripts bulk-renaming with generated strings; UI without a maxlength on the input.","solutions":["Set maxlength=500 (and trim) on the rename input in the UI.","Truncate or reject client-side before the request when length > 500.","If longer names are a real requirement, raise the column size and the check together."],"exampleFix":"// before\nconst name = anyLengthString;\n// after\nconst name = input.value.trim().slice(0, 500);\nif (!name) return; // avoid 543 instead\nawait post(`/api/gallery/${id}/rename`, {name});","handlingStrategy":"validation","validationCode":"const name = input.value.trim();\nif (name.length > 500) return showError('Name too long');\nawait post(`/api/gallery/${id}/rename`, {name});","typeGuard":"const isValidName = (v) => { const s = (v ?? '').trim(); return s.length > 0 && s.length <= 500; };","tryCatchPattern":null,"preventionTips":["maxlength=500 on rename inputs","Trim before measuring length","Reject, don't silently truncate, if the user typed a paragraph by mistake"],"tags":["http","validation","gallery","rename","length-limit"],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}