PdfObject.indirect_reference is not available

Open Beginner friendly
#3,294 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
backend

Research direction

Start by locating the PdfObject and DictionaryObject definitions in pypdf.generic and compare them with the protocol/PdfObject declaration. Reproduce the issue with the minimal Python example, then verify that both objects expose indirect_reference without raising AttributeError.

Written by the indexing model from the issue text.

Description

generic is-bug needs-discussion

Creating a simple PdfObject or DictionaryObject and accessing its indirect_reference attribute fails, although it is part of the protocol/PdfObject class.

Initially discovered while looking at #3293.

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
Linux-6.4.0-150600.23.47-default-x86_64-with-glibc2.38

$ python -c "import pypdf;print(pypdf._debug_versions)"
pypdf==5.5.0, crypt_provider=('cryptography', '44.0.0'), PIL=11.1.0

Code + PDF

This is a minimal, complete example that shows the issue:

from pypdf.generic import DictionaryObject, PdfObject

print(PdfObject().indirect_reference)
print(DictionaryObject().indirect_reference)

Traceback

This is the complete traceback I see:

Traceback (most recent call last):
  File "/home/stefan/tmp/scratches/scratch_6.py", line 3, in <module>
    print(PdfObject().indirect_reference)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PdfObject' object has no attribute 'indirect_reference'
Dominant language
Python
Stars
10.2k
Forks
1.6k
Avg merge
1d 5h
Merged PRs (30d)
81

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from py-pdf/pypdf

All issues in py-pdf/pypdf

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.