Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROB : update_page_form_field_values not failing if no fields #1346

Merged
merged 2 commits into from Sep 18, 2022

Conversation

pubpub-zz
Copy link
Collaborator

fixes #1343

@codecov
Copy link

codecov bot commented Sep 13, 2022

Codecov Report

Base: 94.62% // Head: 94.71% // Increases project coverage by +0.08% 🎉

Coverage data is based on head (e48e821) compared to base (e23b985).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1346      +/-   ##
==========================================
+ Coverage   94.62%   94.71%   +0.08%     
==========================================
  Files          30       30              
  Lines        5118     5185      +67     
  Branches     1052     1061       +9     
==========================================
+ Hits         4843     4911      +68     
  Misses        164      164              
+ Partials      111      110       -1     
Impacted Files Coverage Δ
PyPDF2/_writer.py 91.10% <100.00%> (+0.06%) ⬆️
PyPDF2/_utils.py 99.43% <0.00%> (-0.57%) ⬇️
PyPDF2/_cmap.py 95.08% <0.00%> (-0.03%) ⬇️
PyPDF2/generic/_base.py 100.00% <0.00%> (ø)
PyPDF2/generic/_rectangle.py 100.00% <0.00%> (ø)
PyPDF2/_page.py 95.00% <0.00%> (+0.63%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines 625 to 626
if PG.ANNOTS not in page:
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add the attribute if it doesn't exist, e.g.:

Suggested change
if PG.ANNOTS not in page:
return
if PG.ANNOTS not in page:
page[PG.ANNOTS] = DictionaryObject()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the form has no fields to field, adding the PG.ANNOTS field may be of no use and quite confusing after (looking at the page structure you may think after there is so fields to fill up whereas there isn't)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the form has no fields to field

I guess there was a typo? I don't understand this.

At the very least we should emit a warning ... if we are in strict mode maybe even an exception?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the form has no fields to be filled, adding the PG.ANNOTS field may be of no use and quite confusing after (looking at the page structure you may think after there is so fields to fill up whereas there isn't) ; more consistent with PDF philosophy : if you don't need it, it is not in the dictionary (no fields means logically no PG.ANNOTS entry)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you don't want to add it. It makes sense to me now.

However, looking at it from the users perspective: The user wants to fill a form field that doesn't exist. PyPDF2 executes sucessfully without an exception, without a warning, without a log message. No field is filled. That feels wrong to me.

A warning log message - something like "Filling fields was skipped as the page does not have any annotations" would give the user a chance to fix the code.

@pubpub-zz pubpub-zz closed this Sep 14, 2022
@pubpub-zz pubpub-zz deleted the iss1343 branch September 14, 2022 11:00
@pubpub-zz pubpub-zz restored the iss1343 branch September 16, 2022 15:16
@pubpub-zz pubpub-zz reopened this Sep 16, 2022
@pubpub-zz
Copy link
Collaborator Author

wrongly deleted

@pubpub-zz
Copy link
Collaborator Author

@MartinThoma
Ok for you ?

@MartinThoma
Copy link
Member

Thank you :-)

I've just released, but it will be in the next release :-)

@MartinThoma MartinThoma merged commit 141a765 into py-pdf:main Sep 18, 2022
MartinThoma added a commit that referenced this pull request Sep 25, 2022
New Features (ENH):
-  Addition of optional visitor-functions in extract_text() (#1252)
-  Add metadata.creation_date and modification_date (#1364)
-  Add PageObject.images attribute (#1330)

Bug Fixes (BUG):
-  Lookup index in _xobj_to_image can be ByteStringObject (#1366)
-  \'IndexError: index out of range\' when using extract_text (#1361)
-  Errors in transfer_rotation_to_content() (#1356)

Robustness (ROB):
-  Ensure update_page_form_field_values does not fail if no fields (#1346)

Testing (TST):
-  read_string_from_stream performance (#1355)

Full Changelog: 2.10.9...2.11.0
@pubpub-zz pubpub-zz deleted the iss1343 branch June 24, 2023 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyError: '/Annots' in update_page_form_field_values
2 participants