Skip to content
← Back to activity

Immutable solution version

textractor raises `KeyError: 'Geometry'` when an expense field has an empty value

Version 1Sign in to save

Complete solution

What this covers: I call `textract.start_expense_analysis` on a multi-page invoice PDF stored in S3. The fix that worked: This was a real bug in textractor's expense parser.

textractor raises KeyError: 'Geometry' when an expense field has an empty value

Whats going on

I call textract.start_expense_analysis on a multi-page invoice PDF stored in S3. When I access document.expense_documents, I get KeyError: 'Geometry'. Debugging the textractor package, I found the Geometry part is missing for an ExpenseField whose value is empty (like the PO Number in the screenshot , the key exists but the value cell is blank). Why does an empty cell crash the parse?

What actually fixes it

This was a real bug in textractor's expense parser. Unlike the Forms API, AnalyzeExpense does not return a bounding box for a key that has no attached value , Textract simply omits the Geometry for empty-value fields, and textractor crashed on the missing key instead of handling it. The maintainer (Belval) reproduced and fixed it, and the reporter confirmed on 2023-06-05 that it works fine after the fix. So update textractor to the fixed version. Until then, the workaround is to guard for missing Geometry on expense fields (treat the value as empty string/None) when iterating expense_documents.

Original thread

https://vectle.com/threads/thr_A5-UQWmvhwoQpObK5gVlVw

Evidence

In the thread https://vectle.com/threads/thrA5-UQWmvhwoQpObK5gVlVw, the question was: I call `textract.startexpenseanalysis on a multi-page invoice PDF stored in S3. When I access document.expensedocuments, I get KeyError: 'Geometry'. Debugging the textractor package, I found the Geometry part is missing for an ExpenseField whose value is empty (like the PO Number in the screenshot , the key exists but the value cell is blank). Why does an empty cell crash the parse? The verified resolution was: This was a real bug in textractor's expense parser. Unlike the Forms API, AnalyzeExpense does not return a bounding box for a key that has no attached value , Textract simply omits the Geometry for empty-value fields, and textractor crashed on the missing key instead of handling it. The maintainer (Belval) reproduced and fixed it, and the reporter confirmed on 2023-06-05 that it works fine after the fix. So update textractor to the fixed version. Until then, the workaround is to guard for missing Geometry on expense fields (treat the value as empty string/None) when iterating expense_documents`.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_DyvGC6hrGTXvL6cTvrAurA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">textractor raises `KeyError: &#39;Geometry&#39;` when an expense field has an empty value <span>— Vectle</span></a>