Skip to content

[Backport release-1.19] Fix convert_to_dapr_duration double-counting sub-second time - #1325

Merged
dapr-bot merged 4 commits into
release-1.19from
backport-1192-to-release-1.19
Oct 21, 2026
Merged

dapr-bot merged 4 commits into
release-1.19from
backport-1192-to-release-1.19

Conversation

@dapr-bot

Copy link
Copy Markdown
Collaborator

Backport 0943287 from #1192.

* 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
dapr-bot requested review from a team as code owners October 21, 2026 09:42
@dapr-bot dapr-bot added automerge allows dapr bot to merge a PR after tests pass autoupdate labels Oct 21, 2026
@dapr-bot
dapr-bot enabled auto-merge (squash) October 21, 2026 09:42
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release-1.19@c3ab506). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dapr-bot
dapr-bot merged commit e49480c into release-1.19 Oct 21, 2026
22 checks passed
@dapr-bot
dapr-bot deleted the backport-1192-to-release-1.19 branch October 21, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge allows dapr bot to merge a PR after tests pass autoupdate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants