From 3eb78101a3a61933eb0c25873ef8ed5e059e9f16 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Sun, 23 Nov 2025 21:49:28 +0100 Subject: [PATCH] fix: handle empty category strings as None in update endpoint --- app/routers/items.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/routers/items.py b/app/routers/items.py index 2c2964b..7fb5e34 100644 --- a/app/routers/items.py +++ b/app/routers/items.py @@ -34,16 +34,17 @@ def delete_item(item_id: int, db: Session = Depends(database.get_db)): @router.patch("/{item_id}/category") -def update_item_category(item_id: int, category: str | None, db: Session = Depends(database.get_db)): +def update_item_category(item_id: int, category: str | None = None, db: Session = Depends(database.get_db)): """Update the category of an item""" item = db.query(models.Item).filter(models.Item.id == item_id).first() if not item: raise HTTPException(status_code=404, detail="Item not found") - item.category = category + # Treat empty string as None + item.category = category if category and category.strip() else None db.commit() db.refresh(item) - return {"message": "Category updated", "category": category} + return {"message": "Category updated", "category": item.category} @router.get("/categories/list")