summaryrefslogtreecommitdiff
path: root/kitchen/views.py
diff options
context:
space:
mode:
authorTom Flux <tom@tomflux.xyz>2026-06-23 21:24:09 +0100
committerTom Flux <tom@tomflux.xyz>2026-06-23 21:24:09 +0100
commiteeeb1c5b34c058f2c1a7ea2f3c6b179f503d2aa4 (patch)
tree3633b6f6232ce1f523621b4dd149ba68f5abe759 /kitchen/views.py
parenteed90569f7dafa7eb9c8358c152efac1a49f0405 (diff)
Fix bulk-pantry-add crash on null unit (found in live MCP testing)
End-to-end testing (MCP client -> FastMCP -> Django) surfaced a 500: adding an item with an explicit `unit: null` (as add_to_pantry sends for items without a unit) hit a NOT NULL violation, because `item_data.get("unit", "items")` returns None when the key is present. - views.bulk_pantry_add: `item_data.get("unit") or "items"` — tolerate null/empty unit. - mcp_server add_to_pantry: omit quantity/unit from the payload when unset, so the API applies its own defaults. - test: bulk-add with unit/quantity = null returns 201 (25 pass). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'kitchen/views.py')
-rw-r--r--kitchen/views.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/kitchen/views.py b/kitchen/views.py
index 5fdf041..882f2ef 100644
--- a/kitchen/views.py
+++ b/kitchen/views.py
@@ -576,7 +576,7 @@ def bulk_pantry_add(request):
name = item_data.get("ingredient_name", "").strip()
qty_raw = item_data.get("quantity")
quantity = int(qty_raw) if qty_raw not in (None, "") else None
- unit = item_data.get("unit", "items")
+ unit = item_data.get("unit") or "items" # tolerate null/empty
location = item_data.get("location", "fridge")
expiry_days = item_data.get("expiry_days") # optional override