Skip to content

Fix fractional-second parsing in parse_iso8601 - #11181

Open
adityajai119 wants to merge 1 commit into
celery:mainfrom
adityajai119:fix-iso8601-fractional-seconds
Open

adityajai119 wants to merge 1 commit into
celery:mainfrom
adityajai119:fix-iso8601-fractional-seconds

Conversation

@adityajai119

Copy link
Copy Markdown

parse_iso8601 converted the fractional-second digits directly to an integer microsecond value, so .1 became 1 microsecond instead of 100000 and .12 became 12 instead of 120000. That disagrees with datetime.datetime.fromisoformat and dateutil.parser.isoparse, the replacements named in the deprecation warning.

The fractional part is now right-padded to six digits (and truncated beyond six) before conversion.

Verification: pytest t/unit/utils/test_iso8601.py 10 passed; ruff check celery/utils/iso8601.py t/unit/utils/test_iso8601.py clean.

@atishay-kasliwal atishay-kasliwal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Compared parse_iso8601 with datetime.fromisoformat on 7 timestamps with 0, 1, 2, 6 and 7 fraction digits, with and without an offset. All match now. Master turned .5 into 5 microseconds and raised ValueError for 7 digits.

This branch has not been deployed

No deployments
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.

2 participants