fix: guard page.flatten() for non-fillable PDFs (#240)#243
Merged
Conversation
added 4 commits
March 18, 2026 12:17
page.flatten() requires formenv to be set, which only happens for PDFs with AcroForm fields. For regular PDFs without forms, formenv is None and flatten() raises an error. Added conditional guard to only call flatten() when page.formenv is not None.
- Changed 'img_bytes = None' to 'del img_bytes' to fix reportAssignmentType type error (None not assignable to bytes parameter) - Added PEP 440 version validation to 'make version' using packaging.version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the regression where
page.flatten()crashes for regular (non-fillable) PDFs.Root cause:
flatten()requirespage.formenvto be non-None, but for PDFs without AcroForm fields,init_forms()setsformenv = None(no form data to initialize). The unconditionalpage.flatten()then fails.Fix: Guard with
if page.formenv is not None:before callingflatten(). This ensures:flatten()is called (formenv is set)flatten()is skipped (formenv is None)Verified locally with both
samples/lending_package.pdf(regular) and fillable VA forms.