Repository navigation
Fix parse_date losing a microsecond on some fractional seconds - #2243
Open
aad1tyaaaaa wants to merge 2 commits into
Open
aad1tyaaaaa wants to merge 2 commits into
aad1tyaaaaa wants to merge 2 commits into
Conversation
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix parse_date losing a microsecond on some fractional seconds
Description
libcloud.utils.iso8601.parse_dateconverts the fractional seconds withint(float("0.%s" % fraction) * 1e6). The float product is sometimes just below the integer, so the result comes out one microsecond short:Of all 1,000,000 six-digit fractions, 11,549 were parsed one microsecond short (e.g.
.000249,.000251,.000489).parse_dateis used by many drivers to parse timestamps from provider APIs (EC2, Azure ARM, OpenStack, DigitalOcean, Scaleway, ...).This shows up in the existing tests too: the Scaleway
list_nodes.jsonfixture has"creation_date": "2014-05-22T12:57:22.514299+00:00", whiletest_list_nodes_fills_created_datetimeexpected514298, the value the float conversion produced.The fix takes the microseconds directly from the digits:
int(fraction[:6].ljust(6, "0")). With it, all 1,000,000 six-digit fractions parse exactly. Fractions with more than six digits are still truncated to microseconds, as before.Status
Checklist
black,isort)CHANGES.rstentry)test_parse_date_fractioninlibcloud/test/test_utils.py(the cases that used to come out short fail without this change), and the Scaleway expectation corrected to match its fixture. The utils tests and the compute driver tests that parse dates (EC2, Azure ARM, OpenStack, DigitalOcean, gridscale, Scaleway, vCloud) pass.I used an AI assistant (Claude Code) to help find this bug and write the fix and tests. I reviewed and ran everything myself.