bulk-add-by-name fails: source=shopping violates DB CHECK constraint #100

Closed
opened 2026-04-18 09:11:19 -07:00 by pyr0ball · 0 comments
Owner

Summary

POST /api/v1/inventory/items/bulk-add-by-name always fails with a DB constraint error because it uses source="shopping" which is not in the allowed values.

Steps to reproduce

  1. POST /api/v1/inventory/items/bulk-add-by-name with {"items": [{"name": "onion", "location": "pantry"}]}
  2. Response shows ok: false for every item

Expected

Items are created successfully.

Actual

{"added": 0, "failed": 2, "results": [{"name": "onion", "ok": false, "error": "CHECK constraint failed: source IN (\u2018openfoodfacts\u2019, \u2018manual\u2019, \u2018receipt_ocr\u2019)"}]}

Root cause

app/api/endpoints/inventory.py line 187: get_or_create_product(..., source="shopping") but the products.source column constraint is CHECK (source IN (\u2018openfoodfacts\u2019, \u2018manual\u2019, \u2018receipt_ocr\u2019)). Similarly line 195: add_inventory_item(..., source="shopping") but inventory_items.source constraint is CHECK (source IN (\u2018barcode_scan\u2019, \u2018manual\u2019, \u2018receipt\u2019)).

Fix

Change source="shopping" to source="manual" in both calls, or add shopping to the CHECK constraint via a migration.

## Summary `POST /api/v1/inventory/items/bulk-add-by-name` always fails with a DB constraint error because it uses `source="shopping"` which is not in the allowed values. ## Steps to reproduce 1. `POST /api/v1/inventory/items/bulk-add-by-name` with `{"items": [{"name": "onion", "location": "pantry"}]}` 2. Response shows `ok: false` for every item ## Expected Items are created successfully. ## Actual ```json {"added": 0, "failed": 2, "results": [{"name": "onion", "ok": false, "error": "CHECK constraint failed: source IN (\u2018openfoodfacts\u2019, \u2018manual\u2019, \u2018receipt_ocr\u2019)"}]} ``` ## Root cause `app/api/endpoints/inventory.py` line 187: `get_or_create_product(..., source="shopping")` but the `products.source` column constraint is `CHECK (source IN (\u2018openfoodfacts\u2019, \u2018manual\u2019, \u2018receipt_ocr\u2019))`. Similarly line 195: `add_inventory_item(..., source="shopping")` but `inventory_items.source` constraint is `CHECK (source IN (\u2018barcode_scan\u2019, \u2018manual\u2019, \u2018receipt\u2019))`. ## Fix Change `source="shopping"` to `source="manual"` in both calls, or add `shopping` to the CHECK constraint via a migration.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Circuit-Forge/kiwi#100
No description provided.