Skip to content

Fix: catch RuntimeError alongside ImportError for the optional numpy import - #1909

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
stumpylog:fix/numpy-runtimeerror-baseline
Aug 5, 2026
Merged

Fix: catch RuntimeError alongside ImportError for the optional numpy import#1909
andersonhc merged 1 commit into
py-pdf:masterfrom
stumpylog:fix/numpy-runtimeerror-baseline

Conversation

@stumpylog

@stumpylog stumpylog commented Jul 30, 2026

Copy link
Copy Markdown

Fixes #1908

The optional numpy import in image_parsing.py only caught ImportError. On CPUs numpy's manylinux wheel doesn't support (below its x86-64-v2 baseline as of numpy 2.4.0), import numpy raises RuntimeError instead, which propagated out of import fpdf entirely and crashed every caller, even ones that never touch the numpy-guarded code paths. Both existing call sites (pack_codes_into_bytes(), _has_alpha()) already guard on numpy is not None, so treating RuntimeError the same as ImportError is enough to restore the intended "numpy unavailable, fall back" behavior.

Checklist:

  • A unit test is covering the code added / modified by this PR - N/A, this only widens an except clause around an import statement; reproducing it requires either genuinely unsupported hardware or monkeypatching builtins.__import__, none of which seem feasible or really useful
  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder
  • A mention of the change is present in CHANGELOG.md
  • This PR is ready to be merged

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

@andersonhc

Copy link
Copy Markdown
Collaborator

@allcontributors please add @stumpylog for bug, code

@allcontributors

Copy link
Copy Markdown

@andersonhc

I've put up a pull request to add @stumpylog! 🎉

@andersonhc andersonhc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge. Thank you.

@andersonhc
andersonhc merged commit b30c38c into py-pdf:master Aug 5, 2026
23 checks passed
@stumpylog

Copy link
Copy Markdown
Author

Thanks for the merge. If you happen to get time to cut a release, this would be great to include for our users soon.

@shamoon

shamoon commented Aug 9, 2026

Copy link
Copy Markdown

Hi @andersonhc im one of the other paperless devs, thanks for your work on this project. Is there any chance you would be planning (or willing) to make a release with this change soon? Thanks again

@andersonhc

Copy link
Copy Markdown
Collaborator

Hi @andersonhc im one of the other paperless devs, thanks for your work on this project. Is there any chance you would be planning (or willing) to make a release with this change soon? Thanks again

I am preparing a new release today. Probably a couple hours it should be in pypi.

@shamoon

shamoon commented Aug 9, 2026

Copy link
Copy Markdown

Oh wow thank you!!

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.

Optional numpy import only catches ImportError, so numpy's own RuntimeError on unsupported CPUs becomes fatal

3 participants