Filler.fill_form currently assigns extracted values to PDF widgets positionally — it takes
list(textbox_answers.values()) and assigns them to PDF widgets sorted by visual position
(top-to-bottom, left-to-right), by list order rather than by matching field names.
This works today only because the template's field-dict insertion order happens to line up
with the PDF widget visual order (the upload flow extracts fields in that same order). It's
a fragile, implicit contract: if the field-dict order and PDF widget order ever diverge,
values land in the wrong boxes — a serious failure on official emergency reports.
Changes
- Match extracted values to PDF widgets by field name rather than list position.
- (If full name-matching is out of scope, at minimum document and lock the ordering
contract explicitly and add a guard/test — but name-matching is preferred.)
Acceptance criteria
- Values are placed by field-name match, not list order.
- A test covers the case where field-dict order and PDF widget order differ, proving values
still land correctly.
- Existing fill tests pass.
Note
This is a refactor of working behavior — the current tests pass because of the coincidental
ordering, so changing the matching may require updating them. Handle carefully.
Part of the Pipeline B tracker (#636 ).
Filler.fill_form currently assigns extracted values to PDF widgets positionally — it takes
list(textbox_answers.values()) and assigns them to PDF widgets sorted by visual position
(top-to-bottom, left-to-right), by list order rather than by matching field names.
This works today only because the template's field-dict insertion order happens to line up
with the PDF widget visual order (the upload flow extracts fields in that same order). It's
a fragile, implicit contract: if the field-dict order and PDF widget order ever diverge,
values land in the wrong boxes — a serious failure on official emergency reports.
Changes
contract explicitly and add a guard/test — but name-matching is preferred.)
Acceptance criteria
still land correctly.
Note
This is a refactor of working behavior — the current tests pass because of the coincidental
ordering, so changing the matching may require updating them. Handle carefully.
Part of the Pipeline B tracker (#636 ).