Skip to content

page.annots(): ValueError: orphaned object: parent is None #2479

@cbm755

Description

@cbm755

I'm not sure what the expected behaviour is, but I'm getting a ValueError from .annots():

>> import fitz
>> fitz.version
Out[3]: ('1.22.3', '1.22.0', '20230510000001')

>> doc = fitz.open("DELETE_ME_tam_file_with_runtime_annot_errors.pdf")

>> list(doc[0].annots())
Out[8]: ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File /usr/lib/python3.11/site-packages/IPython/core/formatters.py:706, in PlainTextFormatter.__call__(self, obj)
    699 stream = StringIO()
    700 printer = pretty.RepresentationPrinter(stream, self.verbose,
    701     self.max_width, self.newline,
    702     max_seq_length=self.max_seq_length,
    703     singleton_pprinters=self.singleton_printers,
    704     type_pprinters=self.type_printers,
    705     deferred_pprinters=self.deferred_printers)
--> 706 printer.pretty(obj)
    707 printer.flush()
    708 return stream.getvalue()

File /usr/lib/python3.11/site-packages/IPython/lib/pretty.py:393, in RepresentationPrinter.pretty(self, obj)
    390 for cls in _get_mro(obj_class):
    391     if cls in self.type_pprinters:
    392         # printer registered in self.type_pprinters
--> 393         return self.type_pprinters[cls](obj, self, cycle)
    394     else:
    395         # deferred printer
    396         printer = self._in_deferred_types(cls)

File /usr/lib/python3.11/site-packages/IPython/lib/pretty.py:640, in _seq_pprinter_factory.<locals>.inner(obj, p, cycle)
    638         p.text(',')
    639         p.breakable()
--> 640     p.pretty(x)
    641 if len(obj) == 1 and isinstance(obj, tuple):
    642     # Special case for 1-item tuples.
    643     p.text(',')

File /usr/lib/python3.11/site-packages/IPython/lib/pretty.py:410, in RepresentationPrinter.pretty(self, obj)
    407                         return meth(obj, self, cycle)
    408                 if cls is not object \
    409                         and callable(cls.__dict__.get('__repr__')):
--> 410                     return _repr_pprint(obj, self, cycle)
    412     return _default_pprint(obj, self, cycle)
    413 finally:

File /usr/lib/python3.11/site-packages/IPython/lib/pretty.py:778, in _repr_pprint(obj, p, cycle)
    776 """A pprint that just redirects to the normal repr function."""
    777 # Find newlines and replace them with p.break_()
--> 778 output = repr(obj)
    779 lines = output.splitlines()
    780 with p.group():

File ~/.local/lib/python3.11/site-packages/fitz/fitz.py:8526, in Annot.__repr__(self)
   8525 def __repr__(self):
-> 8526     CheckParent(self)
   8527     return "'%s' annotation on %s" % (self.type[1], str(self.parent))

File ~/.local/lib/python3.11/site-packages/fitz/fitz.py:2975, in CheckParent(o)
   2973 def CheckParent(o: typing.Any):
   2974     if getattr(o, "parent", None) == None:
-> 2975         raise ValueError("orphaned object: parent is None")

ValueError: orphaned object: parent is None

I don't get the error if I send types:

>> list(doc[0].annots(types=[fitz.PDF_ANNOT_WIDGET]))
Out[36]: []

>> list(doc[0].annots(types=[fitz.PDF_ANNOT_POPUP]))
Out[37]: []

>> list(doc[0].annots(types=[fitz.PDF_ANNOT_LINK]))
Out[38]: []

I also don't get the error if reference a page directly:

>> p = doc[0]

>> list(p.annots())
Out[42]: 
['FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'Ink' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'Ink' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf,
 'FreeText' annotation on page 0 of DELETE_ME_tam_file_with_runtime_annot_errors.pdf]

I can't think why p.annots() would be different than doc[0].annots()...

Metadata

Metadata

Assignees

No one assigned

    Labels

    not a bugnot a bug / user error / unable to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions