Repository navigation
[Backport release-1.19] Fix convert_to_dapr_duration double-counting sub-second time - #1325
Merged
Merged
Conversation
* Fix convert_to_dapr_duration double-counting sub-second time
convert_to_dapr_duration() derived the seconds field from
divmod(td.total_seconds(), 60), so it still carried the sub-second
fraction that is also emitted via the ms/us fields, and formatting it
with {:.0f} rounded a fraction >= 0.5 up into an extra whole second. As a
result timedelta(milliseconds=1500) serialized to '0h0m2s500ms0us' (2.5s)
and did not round-trip.
Truncate the whole seconds with int() so the sub-second fraction is only
counted once (via ms/us). Add a regression test.
Signed-off-by: Md. Amdadul Bari Imad <amdadulbari@gmail.com>
* test: cover 1999ms and 1001ms in dapr duration round-trip
Add boundary cases requested in review to
test_convert_timedelta_to_dapr_duration_subsecond: 1999ms verifies a
fraction just under a second is not rounded up to the next whole second,
and 1001ms verifies a tiny fraction is not dropped from the ms field.
Signed-off-by: Md. Amdadul Bari Imad <amdadulbari@gmail.com>
---------
Signed-off-by: Md. Amdadul Bari Imad <amdadulbari@gmail.com>
Co-authored-by: Sam <sam@diagrid.io>
(cherry picked from commit 0943287)
Signed-off-by: dapr-bot <dapr-bot@users.noreply.github.com>
dapr-bot
enabled auto-merge (squash)
October 21, 2026 09:42
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release-1.19 #1325 +/- ##
===============================================
Coverage ? 87.15%
===============================================
Files ? 163
Lines ? 13066
Branches ? 0
===============================================
Hits ? 11388
Misses ? 1678
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
nelson-parente
approved these changes
Oct 21, 2026
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.
Backport 0943287 from #1192.