Avoid parsing timestamp as Decimal #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "decimal-to-integer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.LEDGERformat."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-changesc8452e2ea6toe265d6b51eHmm, actually I'm wrong about OXR rates now being all floating-point. If I
curlthe 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.