Skip to content

Fix td_format rendering of negative durations (#72694) - #72774

Merged
potiuk merged 1 commit into
apache:mainfrom
ShivanshhhG:fix-72694-td-format-negative-duration
Sep 9, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
ShivanshhhG:fix-72694-td-format-negative-duration

Conversation

@ShivanshhhG

Copy link
Copy Markdown
Contributor

closes: #72694

Rationale for this change

Fixes #72694.

td_format in shared/timezones rendered negative timedelta objects as large positive durations (e.g. timedelta(seconds=-3752) rendered as 29d:22h:57M:28s). This occurred because relativedelta days normalization via divmod produced negative months (months=-1, days=+29) which were stripped by positive magnitude filtering (value < 1). Furthermore, numeric negative inputs (e.g. -3752) returned <1s.

What changes are included in this PR?

  1. Updated td_format in shared/timezones/src/airflow_shared/timezones/timezone.py to extract negative sign prefix ("-") and compute duration string using the absolute magnitude of the timedelta or numeric duration.
  2. Added test cases in test_timezone.py verifying negative timedelta and negative numeric inputs format correctly (e.g. td_format(timedelta(seconds=-3752)) returns "-1h:2M:32s", td_format(-3752) returns "-1h:2M:32s", td_format(timedelta(days=-5)) returns "-5d").

Are these changes tested?

Yes. Added unit tests in shared/timezones/tests/timezones/test_timezone.py and verified all 30 timezone unit tests pass.

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@potiuk potiuk added this to the Airflow 3.3.2 milestone Sep 9, 2026
@potiuk
potiuk merged commit 3e8f918 into apache:main Sep 9, 2026
77 checks passed
@boring-cyborg

boring-cyborg Bot commented Sep 9, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-3-test PR Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

td_format renders negative durations as large positive ones

2 participants