odysseus-dev/odysseus · warning · HTTPException

Name cannot be empty

Error message

Name cannot be empty

What it means

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.

Source

Thrown at routes/gallery/gallery_routes.py:486

            except Exception:
                db.rollback()
                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):

View on GitHub (pinned to f9235ebbf1)

Solutions

  1. Require a non-blank name in the UI before enabling submit.
  2. Send the field as exactly "name" with at least one non-whitespace character.
  3. Trim client-side and skip the request entirely when empty.

Example fix

// before
await post(`/api/gallery/${id}/rename`, {name: input.value});
// after
const name = input.value.trim();
if (!name) return showError('Enter a name');
await post(`/api/gallery/${id}/rename`, {name});
Defensive patterns

Strategy: validation

Validate before calling

const name = (input?.value ?? '').trim();
if (!name) return showError('Enter a name');
await post(`/api/gallery/${id}/rename`, {name});

Type guard

const isNonBlankName = (v) => typeof v === 'string' && v.trim().length > 0;

Prevention

When it happens

Trigger: Sending {"name": ""}, {"name": " "}, {}, or {"name": null} in the JSON body of the rename request.

Common situations: UI rename dialog submitted without typing anything; double-submit clearing the input; frontend sending the wrong key (e.g. 'title') so .get() returns None.

Related errors


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