Skip to content

BUG: check whether self._info is not None before accessing its indirect_reference property#3349

Closed
djangovanderheijden wants to merge 2 commits intopy-pdf:mainfrom
djangovanderheijden:main
Closed

BUG: check whether self._info is not None before accessing its indirect_reference property#3349
djangovanderheijden wants to merge 2 commits intopy-pdf:mainfrom
djangovanderheijden:main

Conversation

@djangovanderheijden
Copy link

I ran into the following error whilst compressing identical objects for a specific input PDF:

AttributeError: 'NoneType' object has no attribute 'indirect_reference'

After taking a closer look, it seems self._info is usually checked for None throughout the code in _writer.py. This one specific line seems to have slipped through the cracks.

@djangovanderheijden djangovanderheijden changed the title Bugfix: check whether self._info is not None before accessing its indirect_reference property BUG: check whether self._info is not None before accessing its indirect_reference property Jul 1, 2025
@codecov
Copy link

codecov bot commented Jul 1, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.35%. Comparing base (ad47d50) to head (2dd602f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pypdf/_writer.py 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3349      +/-   ##
==========================================
- Coverage   97.36%   97.35%   -0.01%     
==========================================
  Files          55       55              
  Lines        9824     9825       +1     
  Branches     1794     1795       +1     
==========================================
  Hits         9565     9565              
  Misses        153      153              
- Partials      106      107       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stefan6419846
Copy link
Collaborator

Thanks for the PR. Please add a corresponding test as well.

@stefan6419846 stefan6419846 added the needs-test A test should be added before this PR is merged. label Jul 1, 2025
@djangovanderheijden
Copy link
Author

Unfortunately I don't have the time to set up and figure out unit testing at this moment. The change is simple enough, so if someone could jump in and help out that'd be great. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-test A test should be added before this PR is merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants