Repository navigation
model: parse 1-7 digit fractional seconds in datetime literals on Python 3.10 - #323
Closed
VitorCoelho wants to merge 3 commits into
Closed
VitorCoelho wants to merge 3 commits into
VitorCoelho wants to merge 3 commits into
Conversation
…hon 3.10 On Python 3.10, datetime.fromisoformat accepts only 3 or 6 digit fractions. The padding added in #303 did not cover two cases: - Edm.DateTimeOffset took the first 6 characters after the dot as the fraction, so a shorter fraction swallowed part of the offset and datetimeoffset'...06.5+01:00' failed to parse. - Seven digit fractions (fffffff, allowed by OData V2) were padded but never truncated, so both Edm.DateTime and Edm.DateTimeOffset failed. Normalize the fraction to exactly 6 digits with one shared helper, matching what Python 3.11+ does natively (truncation). Signed-off-by: VitorCoelho <vitorc195@gmail.com>
The new cases fail on Python 3.10 without the previous commit. Signed-off-by: VitorCoelho <vitorc195@gmail.com>
Signed-off-by: VitorCoelho <vitorc195@gmail.com>
Contributor
|
Hi @VitorCoelho,
|
phanak-sap
marked this pull request as draft
October 25, 2026 18:11
Author
|
Thanks for the context. That makes sense: with 3.11 as the minimum the workaround goes away anyway, so there's no point patching it now. |
Contributor
OK, closing on mutual agreement. |
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.
What
Edm.DateTimeandEdm.DateTimeOffsetliteral parsing now normalizes the fractional seconds to exactly 6 digits (pad or truncate) through one small helper,normalize_fractional_seconds, before callingdatetime.fromisoformat.Why
#303 switched to
fromisoformatand padded the fraction, because Python 3.10 (still supported and in the CI matrix) accepts only 3 or 6 digits. Two cases were still broken on 3.10:Edm.DateTimeOffsettook the first 6 characters after the dot as the fraction, so a shorter fraction swallowed part of the offset:datetimeoffset'1976-11-23T03:33:06.5+01:00'anddatetimeoffset'...06.12Z'raisedPyODataModelError.fffffff, allowed by OData V2 and mentioned in theEdm.DateTimedocstring) were padded but never truncated, so both types failed.Python 3.11+ accepts these natively and truncates to microseconds; the helper gives 3.10 the same result.
How it was tested
tests/test_model_v2.py: 7-digitEdm.DateTime;Edm.DateTimeOffsetwith 1, 2 and 7 digits plus offset/Z.