Skip to content

BUG: Fix compress_identical_objects ignoring remove_orphans parameter#3691

Closed
r266-tech wants to merge 1 commit intopy-pdf:mainfrom
r266-tech:fix-remove-orphans-3306
Closed

BUG: Fix compress_identical_objects ignoring remove_orphans parameter#3691
r266-tech wants to merge 1 commit intopy-pdf:mainfrom
r266-tech:fix-remove-orphans-3306

Conversation

@r266-tech
Copy link
Copy Markdown

Description

Fixes #3306

The remove_orphans parameter in PdfWriter.compress_identical_objects() was accepted but never checked, causing orphan objects to always be removed regardless of the parameter value.

Changes

  • pypdf/_writer.py: Wrapped the orphan-removal block with if remove_orphans: check
  • tests/test_writer.py: Added test verifying remove_orphans=False preserves orphan objects and remove_orphans=True removes them

Verification

# Before fix: remove_orphans=False still removed orphans (5 -> 4 objects)
# After fix: remove_orphans=False preserves orphans (5 objects kept)

The remove_orphans parameter was accepted but never checked, causing
orphan objects to always be removed regardless of the parameter value.

Fixes py-pdf#3306
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.43%. Comparing base (04b0a38) to head (59ec10b).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3691   +/-   ##
=======================================
  Coverage   97.43%   97.43%           
=======================================
  Files          55       55           
  Lines       10001    10002    +1     
  Branches     1837     1838    +1     
=======================================
+ Hits         9744     9745    +1     
  Misses        149      149           
  Partials      108      108           

☔ 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
Copy Markdown
Collaborator

stefan6419846 commented Mar 24, 2026

Thanks for the PR. It seems like some checks are still failing.

Additionally, we already have an open PR #3310 for this which hopefully is ready to be merged soon. In the meantime, I will leave your PR as-is.

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.

PdfWriter.compress_identical_objects ignores remove_orphans

3 participants