Fill added documents completely on creation #68
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-add-document-incomplete-fill"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
After filling a client's questionnaire and creating a new document, the generated
.docxwas not fully populated on disk — variables/conditionals showed raw template placeholder text (the bare display name) when opened in an external editor. Opening the document once in Lily silently corrected the file, even with no edits.Root cause
addMultipleDocuments(the only "Add New Document" path) passed the raw client variable pool toreplace_variables_v2. Any variable or conditional absent from that pool — a template-only placeholder, an untouched questionnaire field, or a conditional with no controlling value — was left in raw template form, becauseupdate_sdt_v2leaves an SDT untouched when its variable is missing from the map.openDocumentbuilds a complete per-variable map (defaulting absent entries to""/"false"), which is why opening the doc in the editor fixed it.Fix
addMultipleDocumentsnow builds a complete per-document value map (matching the open/save paths), defaulting absent variables to""/"false"plus schema defaults, via a sharedbuildVariableValueshelper. So every variable resolves on disk at creation time.update_sdt_v2hardening (defense-in-depth): a simple variable absent from the map now blanks to a bookmark, and a schema-backed conditional with an absent controlling variable takes its false branch, instead of leaving the SDT in raw template form. A conditional with no schema entry (branches unknown) is still left untouched. Adds a regression test.selectTemplatestore action. It was the original single-document creation action, orphaned when the TemplatePicker moved to multi-select. It was also the path that already had the correct complete-map logic — keeping a never-exercised reference path is what let the live path silently diverge into this bug.Verification
make test(96 pass, incl. new regression test),make typecheck, andmake lintall clean.