Avoid parsing timestamp as Decimal #1

Open
bsturmfels wants to merge 2 commits from decimal-to-integer into master
Member

Previously, JSON integers were parsed as Decimals, presumably since at some point in the
past, OXR returned some rates as integers. This meant though that the timestamp was also
parsed as a Decimal.

Since Python 3.10, Python no longer implicitly converts Decimals to integers, so the
call to datetime.datetime.fromtimestamp(value) was failing with:

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

Since, OXR rates are now all returned as floating point like below, there's no clear
benefit to parsing integers as Decimals, so I've removed this. Relevant tests pass as
long as I disable the oxrhist.Formats.LEDGER format.

"rates": {
...
"USD": 1.0,
"UYU": 40.255614,
"UZS": 11820.0,
...
},

https://docs.python.org/3.10/whatsnew/3.10.html#other-language-changes

Previously, JSON integers were parsed as Decimals, presumably since at some point in the past, OXR returned some rates as integers. This meant though that the timestamp was also parsed as a Decimal. Since Python 3.10, Python no longer implicitly converts Decimals to integers, so the call to `datetime.datetime.fromtimestamp(value)` was failing with: TypeError: 'decimal.Decimal' object cannot be interpreted as an integer Since, OXR rates are now all returned as floating point like below, there's no clear benefit to parsing integers as Decimals, so I've removed this. Relevant tests pass as long as I disable the `oxrhist.Formats.LEDGER` format. "rates": { ... "USD": 1.0, "UYU": 40.255614, "UZS": 11820.0, ... }, https://docs.python.org/3.10/whatsnew/3.10.html#other-language-changes
Previously, JSON integers were parsed as Decimals, presumably since at some point in the
past, OXR returned some rates as integers. This meant though that the timestamp was also
parsed as a Decimal.

Since Python 3.10, Python no longer implicitly converts Decimals to integers, so the
call to `datetime.datetime.fromtimestamp(value)` was failing with:

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

Since, OXR rates are now all returned as floating point like below, there's no clear
benefit to parsing integers as Decimals, so I've removed this. Relevant tests pass as
long as I disable the `oxrhist.Formats.LEDGER` format.

  "rates": {
    ...
    "USD": 1.0,
    "UYU": 40.255614,
    "UZS": 11820.0,
    ...
  },

https://docs.python.org/3.10/whatsnew/3.10.html#other-language-changes
bsturmfels force-pushed decimal-to-integer from c8452e2ea6 to e265d6b51e 2026-09-08 01:42:42 +00:00 Compare
Author
Member

Hmm, actually I'm wrong about OXR rates now being all floating-point. If I curl the API directly, I get integer results. The responses must be being re-serialized when they're saved to the cache.

Given this it probably does make sense to parse ints as Decimal for consistency. We probably just need to explicitly convert the timestamp back to an integer before reading it.

Hmm, actually I'm wrong about OXR rates now being all floating-point. If I `curl` the API directly, I get integer results. The responses must be being re-serialized when they're saved to the cache. Given this it probably *does* make sense to parse ints as Decimal for consistency. We probably just need to explicitly convert the timestamp back to an integer before reading it.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin decimal-to-integer:decimal-to-integer
git switch decimal-to-integer

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff decimal-to-integer
git switch decimal-to-integer
git rebase master
git switch master
git merge --ff-only decimal-to-integer
git switch decimal-to-integer
git rebase master
git switch master
git merge --no-ff decimal-to-integer
git switch master
git merge --squash decimal-to-integer
git switch master
git merge --ff-only decimal-to-integer
git switch master
git merge decimal-to-integer
git push origin master
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
NPO-Accounting/oxrlib!1
No description provided.