Repository navigation
Accept integer seconds when deserializing datetime.timedelta - #72710
Closed
CaptainAni187 wants to merge 2 commits into
Closed
CaptainAni187 wants to merge 2 commits into
CaptainAni187 wants to merge 2 commits into
Conversation
The serde datetime deserializer accepted only str and float for datetime.timedelta, so a payload carrying whole seconds as an int raised `TypeError: unknown date/time format datetime.timedelta`. The exception is unhandled during scheduler DAG-run creation, which terminates the process. `serialize` writes `total_seconds()` as a float, but a producer that drops the trailing `.0` yields a bare int. The datetime branch a few lines above already accepts `int | float` for the same reason, and the value is passed through `float(data)` regardless, so widening the check is consistent and lossless.
CaptainAni187
requested review from
amoghrajesh,
ashb and
kaxil
as code owners
September 8, 2026 13:41
1 of 2 tasks
Author
|
Closing this — it's already fixed upstream. #72326 landed the same change ( |
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.
Closes: #72319
A
datetime.timedeltapayload whose seconds arrive as anintfails to deserialize:2700.0and"2700"both work. The exception is unhandled during scheduler DAG-run creation, so it takes the scheduler process down.Cause
The deserializer accepts only
str | floatfortimedelta:isinstance(2700, float)isFalse, so an integral payload falls through to theTypeErrorat the end of the function.Change
Widen the check to
str | int | float.Two things make this the natural fix rather than a special case:
datetimebranch a few lines above already acceptsint | float, with a comment explaining it exists so payloads written by a different producer can be read back through serde. This is the same situation one type down.float(data)either way, so an int is handled losslessly. Rejecting it was arbitrary rather than protective.On where the int comes from
I could not reproduce a producer inside this repo that emits the bare int —
serialize()writestotal_seconds()as a float,BaseSerializationdoes the same, and a plain JSON round-trip preserves2700.0. So I am not claiming to have found the exact path from the reported traceback.What is clear is that the value is reachable: any producer that drops a trailing
.0(common across JSON encoders and other languages) yields2700, and the deadline-interval code this was reported from deals in integer seconds by design —VariableIntervaldocuments its variable as "interpreted as seconds" and builds the timedelta viaint(value).Given a one-character-class widening against an unhandled scheduler crash, accepting the int seems clearly right regardless of which producer emitted it. Happy to dig further if you would rather fix this at the producer instead.
Tests
Adds
test_deserialize_timedelta_seconds, parametrised overint,floatandstr. On main theintcase fails with the reportedTypeErrorwhilefloatandstrpass, so the test pins the specific broken path rather than the whole branch.tests/task_sdk/serde/goes from 144 to 147 passed. Nine tests in that directory fail identically before and after this change in my environment, from missing optional dependencies (pyarrow,deltalake,airflow.providers.cncf); they are unrelated to this change.ruff checkandruff formatare clean at the pinned 0.16.4.