Repository navigation
Add pydantic Duration type - #2784
Conversation
|
@yliaog could you please review this ? |
|
OverflowError escapes Pydantic validation uncaught (duration.py in diff): _parse_go_duration() delegates to durationpy.from_str(value), which passes the computed microseconds directly to datetime.timedelta(microseconds=...). For very large inputs that exceed timedelta's range (e.g., "99999999999h" or "1" + "0"*310 + "h"), durationpy.from_str() raises OverflowError — not ValueError. Pydantic v2 only converts ValueError / AssertionError into ValidationError, so Spec(ttl="99999999999h") crashes with an unhandled OverflowError instead of raising ValidationError. Suggested fix: python And add a case like "99999999999h" to test_rejects_invalid_durations. |
|
Thanks @yliaog, good catch. With durationpy 0.10 this did raise OverflowError. 0.11 (our minimum in requirements.txt) already wraps it in DurationError, which is a ValueError, so it was fine there. I added an except OverflowError that raises ValueError anyway, and both of your examples to the invalid durations test. Checked on 0.10 and 0.11, fixed in 03d55e8. |
|
thanks for the PR |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: chala2001, yliaog The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
50b6723
into
kubernetes-client:master
What type of PR is this?
/kind feature
What this PR does / why we need it:
Adds
kubernetes.utils.Duration, a pydantic type for metav1.Duration. It reads and writes Go duration strings like720h0m0s, so custom resource models can use it with CustomObjectsApi.Also adds the missing type hint on
parse_duration.Which issue(s) this PR fixes:
Fixes #2764
Special notes for your reviewer:
Values are stored as timedelta, so anything below a microsecond gets rounded.
Does this PR introduce a user-facing change?