odysseus-dev/odysseus · warning · HTTPException

Name too long

Error message

Name too long

What it means

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.

Source

Thrown at routes/gallery/gallery_routes.py:488

                logger.exception("gallery_replace: DB commit failed")
                raise HTTPException(500, "Image update failed")
            return {"ok": True, "width": img.width, "height": img.height}
        finally:
            db.close()

    # ---- POST /api/gallery/{image_id}/rename ----
    @router.post("/api/gallery/{image_id}/rename")
    async def gallery_rename(request: Request, image_id: str):
        """Rename a gallery photo. Stores the new name in the `prompt`
        column (which serves as the user-facing label for uploaded
        photos that have no AI prompt)."""
        user = get_current_user(request)
        data = await request.json()
        new_name = (data.get("name") or "").strip()
        if not new_name:
            raise HTTPException(400, "Name cannot be empty")
        if len(new_name) > 500:
            raise HTTPException(400, "Name too long")
        db = SessionLocal()
        try:
            img = db.query(GalleryImage).filter(GalleryImage.id == image_id).first()
            if not img:
                raise HTTPException(404, "Image not found")
            if not user or img.owner != user:
                raise HTTPException(403, "Not your image")
            img.prompt = new_name
            db.commit()
            return {"ok": True, "name": new_name}
        finally:
            db.close()

    # ---- POST /api/gallery/{image_id}/rotate ----
    @router.post("/api/gallery/{image_id}/rotate")
    async def gallery_rotate(request: Request, image_id: str):
        """Rotate an image by ±90° or 180°. Updates the file on disk and the
        width/height in the DB. Body: {angle: 90 | -90 | 180}."""

View on GitHub (pinned to f9235ebbf1)

Solutions

  1. Set maxlength=500 (and trim) on the rename input in the UI.
  2. Truncate or reject client-side before the request when length > 500.
  3. If longer names are a real requirement, raise the column size and the check together.

Example fix

// before
const name = anyLengthString;
// after
const name = input.value.trim().slice(0, 500);
if (!name) return; // avoid 543 instead
await post(`/api/gallery/${id}/rename`, {name});
Defensive patterns

Strategy: validation

Validate before calling

const name = input.value.trim();
if (name.length > 500) return showError('Name too long');
await post(`/api/gallery/${id}/rename`, {name});

Type guard

const isValidName = (v) => { const s = (v ?? '').trim(); return s.length > 0 && s.length <= 500; };

Prevention

When it happens

Trigger: Sending a JSON body whose "name" string is longer than 500 characters after trimming.

Common situations: 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.

Related errors


AI-assisted analysis of odysseus-dev/odysseus@f9235ebbf1 (2026-08-14). Data as JSON: /api/errors/be9063a4a6b92585. Report an issue: GitHub.