This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new cc842490b31 Fix airflow db check reporting one fewer retry than it 
will make (#72708)
cc842490b31 is described below

commit cc842490b31525c9f908da3902f6676c6b444689
Author: Y-C <[email protected]>
AuthorDate: Wed Sep 23 07:07:56 2026 +0800

    Fix airflow db check reporting one fewer retry than it will make (#72708)
    
    The warning printed between attempts computed the remaining count as
    retries minus the attempt that had just failed, one lower than the loop's 
own
    stop_after_attempt(1 + retries) budget. The last message before the final
    attempt therefore read "0 retries remain. Will retry in N seconds", telling
    anyone watching a container wait for its database that the command had given
    up at the moment it was still trying.
    
    Co-authored-by: Eason09053360 
<[email protected]>
---
 airflow-core/src/airflow/cli/commands/db_command.py     |  2 +-
 airflow-core/tests/unit/cli/commands/test_db_command.py | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/airflow-core/src/airflow/cli/commands/db_command.py 
b/airflow-core/src/airflow/cli/commands/db_command.py
index 5d04c049652..f6c4403f751 100644
--- a/airflow-core/src/airflow/cli/commands/db_command.py
+++ b/airflow-core/src/airflow/cli/commands/db_command.py
@@ -348,7 +348,7 @@ def check(args):
     retry_delay: int = args.retry_delay
 
     def _warn_remaining_retries(retrystate: RetryCallState):
-        remain = retries - retrystate.attempt_number
+        remain = retries - retrystate.attempt_number + 1
         log.warning("%d retries remain. Will retry in %d seconds", remain, 
retry_delay)
 
     for attempt in Retrying(
diff --git a/airflow-core/tests/unit/cli/commands/test_db_command.py 
b/airflow-core/tests/unit/cli/commands/test_db_command.py
index 22a1202a5d3..df09941b73b 100644
--- a/airflow-core/tests/unit/cli/commands/test_db_command.py
+++ b/airflow-core/tests/unit/cli/commands/test_db_command.py
@@ -829,6 +829,19 @@ class TestCliDb:
             always_fail.assert_has_calls([call()] * (retry + 1))
             sleep.assert_has_calls([call(retry_delay)] * retry)
 
+    def test_check_warns_about_the_retries_that_are_actually_left(self, 
caplog):
+        args = self.parser.parse_args(["db", "check", "--retry", "3", 
"--retry-delay", "9"])
+        always_fail = Mock(side_effect=OperationalError("", None, None))
+
+        with patch("time.sleep", new=MagicMock()), 
patch("airflow.utils.db.check", new=always_fail):
+            with pytest.raises(OperationalError):
+                db_command.check(args)
+
+        assert "3 retries remain. Will retry in 9 seconds" in caplog
+        assert "2 retries remain. Will retry in 9 seconds" in caplog
+        assert "1 retries remain. Will retry in 9 seconds" in caplog
+        assert "0 retries remain. Will retry in 9 seconds" not in caplog
+
 
 class TestCLIDBClean:
     @classmethod

Reply via email to