Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] core: inconsistent pypdf metadata in 5.1
Even if 5.1 is not technically supported, debuntu might switch to it any moment and we don't know if / when upstream will fix it, so it's not worth the time bomb. While technically it was always typed such, since py-pdf/pypdf#2820 it looks like `_info` is a lot more likely to be `None` as e.g. `clone_reader_document_root` now starts with unsetting `_info_obj` and never re-sets it. Except `add_metadata` was not updated to handle this case, likely because mypy interprets `assert isinstance(self._info, DictionaryObject)` as a type narrowing and trusts the developer, thus does not report the type mismatch... and the assertion ends up blowing in the user's face at runtime with a simple >>> r = pypdf.PdfReader(some_pdf_document) >>> w = pypdf.PdfWriter() >>> w.clone_reader_document_root(r) >>> w.add_metadata({"/foo": "bar"}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "lib/python3.12/site-packages/pypdf/_writer.py", line 1622, in add_metadata assert isinstance(self._info, DictionaryObject) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError This is rather inconsiderate, so monkeypatch `add_metadata` to handle the case where `_info` exists and is `None`. Most of the credit goes to juwu for uncovering the issue. opw-4372052 opw-4426881 Fixes odoo#185673 X-original-commit: 1fb35ad Co-authored-by: Junqi <juwu@odoo.com>
- Loading branch information