OCR approval fails: receipt_ocr not valid for inventory_items.source constraint #101

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

Summary

POST /api/v1/receipts/{id}/ocr/approve will fail when trying to create inventory items because ocr.py uses source="receipt_ocr" which is not in the inventory_items.source CHECK constraint.

Steps to reproduce

  1. Upload a receipt and trigger OCR
  2. Call POST /api/v1/receipts/{id}/ocr/approve
  3. Observe 500 Internal Server Error when items are committed

Expected

Inventory items are created from OCR line items.

Actual

sqlite3.IntegrityError: CHECK constraint failed: source IN (\u2018barcode_scan\u2019, \u2018manual\u2019, \u2018receipt\u2019)

Root cause

app/api/endpoints/ocr.py line 222: store.add_inventory_item(..., source="receipt_ocr") but the inventory_items.source column constraint only allows (barcode_scan, manual, receipt). The value receipt_ocr is only valid for the products.source constraint.

Fix

Change source="receipt_ocr" to source="receipt" in ocr.py line 222 for the add_inventory_item call. Products can keep source="receipt_ocr".

## Summary `POST /api/v1/receipts/{id}/ocr/approve` will fail when trying to create inventory items because `ocr.py` uses `source="receipt_ocr"` which is not in the `inventory_items.source` CHECK constraint. ## Steps to reproduce 1. Upload a receipt and trigger OCR 2. Call `POST /api/v1/receipts/{id}/ocr/approve` 3. Observe 500 Internal Server Error when items are committed ## Expected Inventory items are created from OCR line items. ## Actual `sqlite3.IntegrityError: CHECK constraint failed: source IN (\u2018barcode_scan\u2019, \u2018manual\u2019, \u2018receipt\u2019)` ## Root cause `app/api/endpoints/ocr.py` line 222: `store.add_inventory_item(..., source="receipt_ocr")` but the `inventory_items.source` column constraint only allows `(barcode_scan, manual, receipt)`. The value `receipt_ocr` is only valid for the `products.source` constraint. ## Fix Change `source="receipt_ocr"` to `source="receipt"` in `ocr.py` line 222 for the `add_inventory_item` call. Products can keep `source="receipt_ocr"`.
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#101
No description provided.