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 fb8779b7dd1 Fix misleading error for malformed version in airflow db 
downgrade (#72331)
fb8779b7dd1 is described below

commit fb8779b7dd153d74ef049ac515bf0ae67c74d084
Author: Henry Chen <[email protected]>
AuthorDate: Mon Sep 7 18:08:55 2026 +0800

    Fix misleading error for malformed version in airflow db downgrade (#72331)
    
    The downgrade command skipped the version-format check that migrate
    performs, so a typo in --to-version surfaced as "Downgrading to version
    X is not supported". That reads as if the version exists and downgrading
    to it is unsupported, sending users to the docs instead of to their
    typo. --from-version had the same gap.
---
 .../src/airflow/cli/commands/db_command.py         |  8 ++++++
 .../tests/unit/cli/commands/test_db_command.py     | 29 +++++++++++++++++++++-
 2 files changed, 36 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 54de07299c6..5d04c049652 100644
--- a/airflow-core/src/airflow/cli/commands/db_command.py
+++ b/airflow-core/src/airflow/cli/commands/db_command.py
@@ -174,10 +174,18 @@ def run_db_downgrade_command(args, command, 
revision_heads_map: dict[str, str]):
     if args.from_revision:
         from_revision = args.from_revision
     elif args.from_version:
+        try:
+            parse_version(args.from_version)
+        except InvalidVersion:
+            raise SystemExit(f"Invalid version {args.from_version!r} supplied 
as `--from-version`.")
         from_revision = _get_version_revision(args.from_version, 
revision_heads_map=revision_heads_map)
         if not from_revision:
             raise SystemExit(f"Unknown version {args.from_version!r} supplied 
as `--from-version`.")
     if args.to_version:
+        try:
+            parse_version(args.to_version)
+        except InvalidVersion:
+            raise SystemExit(f"Invalid version {args.to_version!r} supplied as 
`--to-version`.")
         to_revision = _get_version_revision(args.to_version, 
revision_heads_map=revision_heads_map)
         if not to_revision:
             raise SystemExit(f"Downgrading to version {args.to_version} is not 
supported.")
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 e6168605a3f..22a1202a5d3 100644
--- a/airflow-core/tests/unit/cli/commands/test_db_command.py
+++ b/airflow-core/tests/unit/cli/commands/test_db_command.py
@@ -641,6 +641,28 @@ class TestCliDb:
                 },
                 "not supported",
             ),
+            (
+                {
+                    "to_revision": None,
+                    "to_version": "abc",
+                    "from_revision": None,
+                    "from_version": None,
+                    "show_sql_only": False,
+                    "yes": True,
+                },
+                "Invalid version 'abc' supplied as `--to-version`",
+            ),
+            (
+                {
+                    "to_revision": "abc1",
+                    "to_version": None,
+                    "from_revision": None,
+                    "from_version": "abc",
+                    "show_sql_only": True,
+                    "yes": True,
+                },
+                "Invalid version 'abc' supplied as `--from-version`",
+            ),
             (
                 {
                     "to_revision": None,
@@ -726,7 +748,12 @@ class TestCliDb:
                 ["-y", "--to-revision", "abc", "--from-version", "2.2.0", 
"--from-revision", "abc"],
                 "may not be combined",
             ),
-            (["-y", "--to-version", "abc"], r"Downgrading to .* not 
supported\."),
+            (["-y", "--to-version", "2.1.25"], r"Downgrading to .* not 
supported\."),
+            (["-y", "--to-version", "abc"], "Invalid version 'abc' supplied as 
`--to-version`"),
+            (
+                ["-y", "--to-revision", "abc1", "--from-version", "abc", "-s"],
+                "Invalid version 'abc' supplied as `--from-version`",
+            ),
             (["-y"], "Must provide either"),
         ],
     )

Reply via email to