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

bugraoz 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 6f1a20f397e Simplify error handling and include environment to version 
command (#56069)
6f1a20f397e is described below

commit 6f1a20f397efe5e48b28a31ce18b1fb06004903c
Author: Bugra Ozturk <[email protected]>
AuthorDate: Thu Sep 25 19:00:24 2025 +0200

    Simplify error handling and include environment to version command (#56069)
    
    * Simplify error handling and include environment to version command
    
    * Fix version command test to handle exceptions without raising SystemExit
    
    * Add remote option to version command for fetching Airflow version from 
remote server
---
 airflow-ctl/docs/images/command_hashes.txt         |  2 +-
 airflow-ctl/docs/images/output_version.svg         | 59 +++++++++++++---------
 airflow-ctl/src/airflowctl/ctl/cli_config.py       | 13 ++++-
 .../src/airflowctl/ctl/commands/version_command.py |  8 +--
 .../ctl/commands/test_version_command.py           | 11 ++--
 5 files changed, 55 insertions(+), 38 deletions(-)

diff --git a/airflow-ctl/docs/images/command_hashes.txt 
b/airflow-ctl/docs/images/command_hashes.txt
index 87a08f62a58..49725974d0c 100644
--- a/airflow-ctl/docs/images/command_hashes.txt
+++ b/airflow-ctl/docs/images/command_hashes.txt
@@ -10,5 +10,5 @@ jobs:7f8680afff230eb9940bc7fca727bd52
 pools:03fc7d948cbecf16ff8d640eb8f0ce43
 providers:1c0afb2dff31d93ab2934b032a2250ab
 variables:0b04188937b3c364204ef4cc9a541c62
-version:000176f03a175890b12181c8569e2d0f
+version:d4a7a6229b3a204f114283b62eac789b
 auth login:5277c653ff6dce51f37472dc0bda9775
diff --git a/airflow-ctl/docs/images/output_version.svg 
b/airflow-ctl/docs/images/output_version.svg
index 8a1da141ff4..a7ce436c8b8 100644
--- a/airflow-ctl/docs/images/output_version.svg
+++ b/airflow-ctl/docs/images/output_version.svg
@@ -1,4 +1,4 @@
-<svg class="rich-terminal" viewBox="0 0 811 196.39999999999998" 
xmlns="http://www.w3.org/2000/svg";>
+<svg class="rich-terminal" viewBox="0 0 811 269.6" 
xmlns="http://www.w3.org/2000/svg";>
     <!-- Generated with Rich https://www.textualize.io -->
     <style>
 
@@ -19,62 +19,75 @@
         font-weight: 700;
     }
 
-    .terminal-3100774986-matrix {
+    .terminal-3399644434-matrix {
         font-family: Fira Code, monospace;
         font-size: 20px;
         line-height: 24.4px;
         font-variant-east-asian: full-width;
     }
 
-    .terminal-3100774986-title {
+    .terminal-3399644434-title {
         font-size: 18px;
         font-weight: bold;
         font-family: arial;
     }
 
-    .terminal-3100774986-r1 { fill: #ff8700 }
-.terminal-3100774986-r2 { fill: #c5c8c6 }
-.terminal-3100774986-r3 { fill: #808080 }
-.terminal-3100774986-r4 { fill: #68a0b3 }
+    .terminal-3399644434-r1 { fill: #ff8700 }
+.terminal-3399644434-r2 { fill: #c5c8c6 }
+.terminal-3399644434-r3 { fill: #808080 }
+.terminal-3399644434-r4 { fill: #68a0b3 }
+.terminal-3399644434-r5 { fill: #00af87 }
     </style>
 
     <defs>
-    <clipPath id="terminal-3100774986-clip-terminal">
-      <rect x="0" y="0" width="792.0" height="145.39999999999998" />
+    <clipPath id="terminal-3399644434-clip-terminal">
+      <rect x="0" y="0" width="792.0" height="218.6" />
     </clipPath>
-    <clipPath id="terminal-3100774986-line-0">
+    <clipPath id="terminal-3399644434-line-0">
     <rect x="0" y="1.5" width="793" height="24.65"/>
             </clipPath>
-<clipPath id="terminal-3100774986-line-1">
+<clipPath id="terminal-3399644434-line-1">
     <rect x="0" y="25.9" width="793" height="24.65"/>
             </clipPath>
-<clipPath id="terminal-3100774986-line-2">
+<clipPath id="terminal-3399644434-line-2">
     <rect x="0" y="50.3" width="793" height="24.65"/>
             </clipPath>
-<clipPath id="terminal-3100774986-line-3">
+<clipPath id="terminal-3399644434-line-3">
     <rect x="0" y="74.7" width="793" height="24.65"/>
             </clipPath>
-<clipPath id="terminal-3100774986-line-4">
+<clipPath id="terminal-3399644434-line-4">
     <rect x="0" y="99.1" width="793" height="24.65"/>
             </clipPath>
+<clipPath id="terminal-3399644434-line-5">
+    <rect x="0" y="123.5" width="793" height="24.65"/>
+            </clipPath>
+<clipPath id="terminal-3399644434-line-6">
+    <rect x="0" y="147.9" width="793" height="24.65"/>
+            </clipPath>
+<clipPath id="terminal-3399644434-line-7">
+    <rect x="0" y="172.3" width="793" height="24.65"/>
+            </clipPath>
     </defs>
 
-    <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" 
x="1" y="1" width="809" height="194.4" rx="8"/>
+    <rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" 
x="1" y="1" width="809" height="267.6" rx="8"/>
             <g transform="translate(26,22)">
             <circle cx="0" cy="0" r="7" fill="#ff5f57"/>
             <circle cx="22" cy="0" r="7" fill="#febc2e"/>
             <circle cx="44" cy="0" r="7" fill="#28c840"/>
             </g>
         
-    <g transform="translate(9, 41)" 
clip-path="url(#terminal-3100774986-clip-terminal)">
+    <g transform="translate(9, 41)" 
clip-path="url(#terminal-3399644434-clip-terminal)">
     
-    <g class="terminal-3100774986-matrix">
-    <text class="terminal-3100774986-r1" x="0" y="20" textLength="73.2" 
clip-path="url(#terminal-3100774986-line-0)">Usage:</text><text 
class="terminal-3100774986-r3" x="85.4" y="20" textLength="219.6" 
clip-path="url(#terminal-3100774986-line-0)">airflowctl&#160;version</text><text
 class="terminal-3100774986-r2" x="305" y="20" textLength="24.4" 
clip-path="url(#terminal-3100774986-line-0)">&#160;[</text><text 
class="terminal-3100774986-r4" x="329.4" y="20" textLength="24.4" 
clip-path="url [...]
-</text><text class="terminal-3100774986-r2" x="793" y="44.4" textLength="12.2" 
clip-path="url(#terminal-3100774986-line-1)">
-</text><text class="terminal-3100774986-r2" x="0" y="68.8" textLength="292.8" 
clip-path="url(#terminal-3100774986-line-2)">Show&#160;version&#160;information</text><text
 class="terminal-3100774986-r2" x="793" y="68.8" textLength="12.2" 
clip-path="url(#terminal-3100774986-line-2)">
-</text><text class="terminal-3100774986-r2" x="793" y="93.2" textLength="12.2" 
clip-path="url(#terminal-3100774986-line-3)">
-</text><text class="terminal-3100774986-r1" x="0" y="117.6" textLength="97.6" 
clip-path="url(#terminal-3100774986-line-4)">Options:</text><text 
class="terminal-3100774986-r2" x="793" y="117.6" textLength="12.2" 
clip-path="url(#terminal-3100774986-line-4)">
-</text><text class="terminal-3100774986-r4" x="24.4" y="142" textLength="24.4" 
clip-path="url(#terminal-3100774986-line-5)">-h</text><text 
class="terminal-3100774986-r2" x="48.8" y="142" textLength="24.4" 
clip-path="url(#terminal-3100774986-line-5)">,&#160;</text><text 
class="terminal-3100774986-r4" x="73.2" y="142" textLength="73.2" 
clip-path="url(#terminal-3100774986-line-5)">--help</text><text 
class="terminal-3100774986-r2" x="170.8" y="142" textLength="378.2" 
clip-path="url(#terminal [...]
+    <g class="terminal-3399644434-matrix">
+    <text class="terminal-3399644434-r1" x="0" y="20" textLength="73.2" 
clip-path="url(#terminal-3399644434-line-0)">Usage:</text><text 
class="terminal-3399644434-r3" x="85.4" y="20" textLength="219.6" 
clip-path="url(#terminal-3399644434-line-0)">airflowctl&#160;version</text><text
 class="terminal-3399644434-r2" x="305" y="20" textLength="24.4" 
clip-path="url(#terminal-3399644434-line-0)">&#160;[</text><text 
class="terminal-3399644434-r4" x="329.4" y="20" textLength="24.4" 
clip-path="url [...]
+</text><text class="terminal-3399644434-r2" x="793" y="44.4" textLength="12.2" 
clip-path="url(#terminal-3399644434-line-1)">
+</text><text class="terminal-3399644434-r2" x="0" y="68.8" textLength="292.8" 
clip-path="url(#terminal-3399644434-line-2)">Show&#160;version&#160;information</text><text
 class="terminal-3399644434-r2" x="793" y="68.8" textLength="12.2" 
clip-path="url(#terminal-3399644434-line-2)">
+</text><text class="terminal-3399644434-r2" x="793" y="93.2" textLength="12.2" 
clip-path="url(#terminal-3399644434-line-3)">
+</text><text class="terminal-3399644434-r1" x="0" y="117.6" textLength="97.6" 
clip-path="url(#terminal-3399644434-line-4)">Options:</text><text 
class="terminal-3399644434-r2" x="793" y="117.6" textLength="12.2" 
clip-path="url(#terminal-3399644434-line-4)">
+</text><text class="terminal-3399644434-r4" x="24.4" y="142" textLength="24.4" 
clip-path="url(#terminal-3399644434-line-5)">-h</text><text 
class="terminal-3399644434-r2" x="48.8" y="142" textLength="24.4" 
clip-path="url(#terminal-3399644434-line-5)">,&#160;</text><text 
class="terminal-3399644434-r4" x="73.2" y="142" textLength="73.2" 
clip-path="url(#terminal-3399644434-line-5)">--help</text><text 
class="terminal-3399644434-r2" x="256.2" y="142" textLength="378.2" 
clip-path="url(#terminal [...]
+</text><text class="terminal-3399644434-r4" x="24.4" y="166.4" 
textLength="24.4" clip-path="url(#terminal-3399644434-line-6)">-e</text><text 
class="terminal-3399644434-r2" x="48.8" y="166.4" textLength="24.4" 
clip-path="url(#terminal-3399644434-line-6)">,&#160;</text><text 
class="terminal-3399644434-r4" x="73.2" y="166.4" textLength="61" 
clip-path="url(#terminal-3399644434-line-6)">--env</text><text 
class="terminal-3399644434-r5" x="146.4" y="166.4" textLength="36.6" 
clip-path="url(#term [...]
+</text><text class="terminal-3399644434-r4" x="24.4" y="190.8" 
textLength="97.6" 
clip-path="url(#terminal-3399644434-line-7)">--remote</text><text 
class="terminal-3399644434-r2" x="256.2" y="190.8" textLength="536.8" 
clip-path="url(#terminal-3399644434-line-7)">Fetch&#160;the&#160;Airflow&#160;version&#160;in&#160;remote&#160;server,&#160;</text><text
 class="terminal-3399644434-r2" x="793" y="190.8" textLength="12.2" 
clip-path="url(#terminal-3399644434-line-7)">
+</text><text class="terminal-3399644434-r2" x="0" y="215.2" textLength="597.8" 
clip-path="url(#terminal-3399644434-line-8)">otherwise&#160;only&#160;shows&#160;the&#160;local&#160;airflowctl&#160;version</text><text
 class="terminal-3399644434-r2" x="793" y="215.2" textLength="12.2" 
clip-path="url(#terminal-3399644434-line-8)">
 </text>
     </g>
     </g>
diff --git a/airflow-ctl/src/airflowctl/ctl/cli_config.py 
b/airflow-ctl/src/airflowctl/ctl/cli_config.py
index bfef454d134..1c9d397fe1b 100644
--- a/airflow-ctl/src/airflowctl/ctl/cli_config.py
+++ b/airflow-ctl/src/airflowctl/ctl/cli_config.py
@@ -289,6 +289,14 @@ ARG_CONFIG_VERBOSE = Arg(
     action="store_true",
 )
 
+# Version Command Args
+ARG_REMOTE = Arg(
+    flags=("--remote",),
+    help="Fetch the Airflow version in remote server, otherwise only shows the 
local airflowctl version",
+    default=False,
+    action="store_true",
+)
+
 
 class ActionCommand(NamedTuple):
     """Single CLI command."""
@@ -849,7 +857,10 @@ core_commands: list[CLICommand] = [
         help="Show version information",
         description="Show version information",
         
func=lazy_load_command("airflowctl.ctl.commands.version_command.version_info"),
-        args=(),
+        args=(
+            ARG_AUTH_ENVIRONMENT,
+            ARG_REMOTE,
+        ),
     ),
     GroupCommand(
         name="variables",
diff --git a/airflow-ctl/src/airflowctl/ctl/commands/version_command.py 
b/airflow-ctl/src/airflowctl/ctl/commands/version_command.py
index 8eae1fcea39..bfaa49a6682 100644
--- a/airflow-ctl/src/airflowctl/ctl/commands/version_command.py
+++ b/airflow-ctl/src/airflowctl/ctl/commands/version_command.py
@@ -16,8 +16,6 @@
 # under the License.
 from __future__ import annotations
 
-import sys
-
 import rich
 
 from airflowctl import __version__ as airflowctl_version
@@ -28,11 +26,9 @@ from airflowctl.api.client import NEW_API_CLIENT, 
ClientKind, provide_api_client
 def version_info(arg, api_client=NEW_API_CLIENT):
     """Get version information."""
     version_dict = {"airflowctl_version": airflowctl_version}
-    try:
+    if arg.remote:
         version_response = api_client.version.get()
         version_dict.update(version_response.model_dump())
         rich.print(version_dict)
-    except Exception as e:
-        rich.print(f"[red]Error fetching version information: {e}[/red]")
+    else:
         rich.print(version_dict)
-        sys.exit(1)
diff --git a/airflow-ctl/tests/airflow_ctl/ctl/commands/test_version_command.py 
b/airflow-ctl/tests/airflow_ctl/ctl/commands/test_version_command.py
index b5deacabb1b..fee0487d3f7 100644
--- a/airflow-ctl/tests/airflow_ctl/ctl/commands/test_version_command.py
+++ b/airflow-ctl/tests/airflow_ctl/ctl/commands/test_version_command.py
@@ -48,19 +48,16 @@ class TestVersionCommand:
 
     parser = cli_parser.get_parser()
 
-    def test_ctl_version(self, mock_client):
+    def test_ctl_version_remote(self, mock_client):
         with redirect_stdout(StringIO()) as stdout:
-            version_info(self.parser.parse_args(["version"]), 
api_client=mock_client)
+            version_info(self.parser.parse_args(["version", "--remote"]), 
api_client=mock_client)
             assert "version" in stdout.getvalue()
             assert "git_version" in stdout.getvalue()
             assert "airflowctl_version" in stdout.getvalue()
 
-    def test_ctl_version_exception(self, mock_client):
+    def test_ctl_version_only_local_version(self, mock_client):
         """Test the version command with an exception."""
-        mock_client.version.get.side_effect = Exception("Test exception")
         with redirect_stdout(StringIO()) as stdout:
-            with pytest.raises(SystemExit):
-                version_info(self.parser.parse_args(["version"]), 
api_client=mock_client)
+            version_info(self.parser.parse_args(["version"]), 
api_client=mock_client)
             output = stdout.getvalue()
-        assert "Error fetching version information: Test exception" in output
         assert "airflowctl_version" in output

Reply via email to