Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'decimal.Decimal' object cannot be interpreted as an integer #774

Closed
MartinThoma opened this issue Apr 17, 2022 · 0 comments · Fixed by #813
Closed

TypeError: 'decimal.Decimal' object cannot be interpreted as an integer #774

MartinThoma opened this issue Apr 17, 2022 · 0 comments · Fixed by #813
Assignees
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF

Comments

@MartinThoma
Copy link
Member

While trying to improve test coverage, I think I found a bug.

Environment

$ python -m platform 
Linux-5.4.0-107-generic-x86_64-with-glibc2.31

$ python -c "import PyPDF2;print(PyPDF2.__version__)"
1.27.5

Code

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

>>> from PyPDF2 import xmp
>>> cls = xmp.XmpInformation
>>> cls._converter_date("2021-04-28T12:23:34.123Z")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/moose/.pyenv/versions/3.10.2/lib/python3.10/site-packages/PyPDF2/xmp.py", line 109, in _converter_date
    dt = datetime.datetime(year, month, day, hour, minute, seconds, milliseconds)
TypeError: 'decimal.Decimal' object cannot be interpreted as an integer

Problem analysis / Fix

The issue seems to be this line:

second = decimal.Decimal(m.group("second") or "0")

I guess that we can simply convert seconds and milliseconds to float

@MartinThoma MartinThoma added the is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF label Apr 17, 2022
@MartinThoma MartinThoma self-assigned this Apr 17, 2022
MartinThoma added a commit that referenced this issue Apr 24, 2022
Fix: Convert decimal to int before passing it to datetime

Closes #774
MartinThoma added a commit that referenced this issue Apr 24, 2022
Fix: Convert decimal to int before passing it to datetime

Closes #774
VictorCarlquist pushed a commit to VictorCarlquist/PyPDF2 that referenced this issue Apr 29, 2022
Fix: Convert decimal to int before passing it to datetime

Closes py-pdf#774
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant