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

shahar1 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 3204b6ebebb Fix enum names and non-ISO dates in airflowctl dags output 
(#76354)
3204b6ebebb is described below

commit 3204b6ebebbd83d69e1203a52a78e85692d2cf5f
Author: Y-C <[email protected]>
AuthorDate: Fri Nov 6 13:52:36 2026 +0800

    Fix enum names and non-ISO dates in airflowctl dags output (#76354)
    
    `dags pause`, `unpause`, `drain` and `next-execution` printed
    "DagSchedulingState.ACTIVE" and "2024-12-31 23:59:59+00:00" with
    `-o json`, so scripts comparing against the API values never matched,
    and the output disagreed with `dags get` for the same Dag.
---
 .../src/airflowctl/ctl/commands/dag_command.py     |  5 ++--
 .../airflow_ctl/ctl/commands/test_dag_command.py   | 27 ++++++++++++++--------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/airflow-ctl/src/airflowctl/ctl/commands/dag_command.py 
b/airflow-ctl/src/airflowctl/ctl/commands/dag_command.py
index 2dc051769bd..04c0e42cd10 100644
--- a/airflow-ctl/src/airflowctl/ctl/commands/dag_command.py
+++ b/airflow-ctl/src/airflowctl/ctl/commands/dag_command.py
@@ -58,7 +58,7 @@ def update_dag_state(
         rich.print(f"[red]Error while trying to {operation} Dag {dag_id}: 
{e}[/red]", file=sys.stderr)
         sys.exit(1)
 
-    response_dict = response.model_dump()
+    response_dict = response.model_dump(mode="json")
     # Status lines go to stderr so stdout carries only the --output data (e.g. 
JSON for jq).
     rich.print(f"[green]Dag {operation} successful {dag_id}[/green]", 
file=sys.stderr)
     rich.print("[green]Further Dag details:[/green]", file=sys.stderr)
@@ -119,7 +119,8 @@ def next_execution(args, api_client=NEW_API_CLIENT) -> dict 
| None:
         rich.print(f"[red]Error retrieving Dag {args.dag_id}: {e}[/red]")
         sys.exit(1)
 
-    next_exec_data = {field: getattr(response, field) for field in 
_NEXT_EXECUTION_FIELDS}
+    response_dict = response.model_dump(mode="json")
+    next_exec_data = {field: response_dict[field] for field in 
_NEXT_EXECUTION_FIELDS}
 
     if all(value is None for value in next_exec_data.values()):
         rich.print(f"[yellow]No upcoming run scheduled for Dag 
{args.dag_id}.[/yellow]")
diff --git a/airflow-ctl/tests/airflow_ctl/ctl/commands/test_dag_command.py 
b/airflow-ctl/tests/airflow_ctl/ctl/commands/test_dag_command.py
index 09f6b3b43d4..b9957333314 100644
--- a/airflow-ctl/tests/airflow_ctl/ctl/commands/test_dag_command.py
+++ b/airflow-ctl/tests/airflow_ctl/ctl/commands/test_dag_command.py
@@ -292,10 +292,10 @@ class TestDagCommands:
     def test_update_dag_state_json_output_is_parseable(
         self, operation, response_attr, api_client_maker, capsys
     ):
-        dag_response = getattr(self, response_attr)
+        response_json = getattr(self, response_attr).model_dump(mode="json")
         api_client = api_client_maker(
             path=f"/api/v2/dags/{self.dag_id}",
-            response_json=dag_response.model_dump(mode="json"),
+            response_json=response_json,
             expected_http_status_code=200,
             kind=ClientKind.CLI,
         )
@@ -304,7 +304,10 @@ class TestDagCommands:
             api_client=api_client,
         )
         captured = capsys.readouterr()
-        assert json.loads(captured.out)[0]["dag_id"] == self.dag_id
+        output = json.loads(captured.out)[0]
+        assert output["dag_id"] == self.dag_id
+        assert output["scheduling_state"] == response_json["scheduling_state"]
+        assert output["last_parsed_time"] == response_json["last_parsed_time"]
         assert _normalize_rich_output(captured.err) == (
             f"Dag {operation} successful {self.dag_id} Further Dag details:"
         )
@@ -328,21 +331,25 @@ class TestDagCommands:
         assert error_message in _normalize_rich_output(captured.err)
         assert error_message not in _normalize_rich_output(captured.out)
 
-    def test_next_execution(self, api_client_maker):
+    def test_next_execution(self, api_client_maker, capsys):
         api_client = api_client_maker(
             path=f"/api/v2/dags/{self.dag_id}",
             response_json=self.dag_response_paused.model_dump(mode="json"),
             expected_http_status_code=200,
             kind=ClientKind.CLI,
         )
-        result = dag_command.next_execution(
-            self.parser.parse_args(["dags", "next-execution", self.dag_id]),
+        dag_command.next_execution(
+            self.parser.parse_args(["dags", "next-execution", self.dag_id, 
"--output", "json"]),
             api_client=api_client,
         )
-        assert result["next_dagrun_logical_date"] == datetime.datetime(2025, 
1, 1, 0, 0, 0)
-        assert result["next_dagrun_data_interval_start"] == 
datetime.datetime(2025, 1, 1, 0, 0, 0)
-        assert result["next_dagrun_data_interval_end"] == 
datetime.datetime(2025, 1, 1, 0, 0, 0)
-        assert result["next_dagrun_run_after"] == datetime.datetime(2025, 1, 
1, 0, 0, 0)
+        assert json.loads(capsys.readouterr().out) == [
+            {
+                "next_dagrun_logical_date": "2025-01-01T00:00:00",
+                "next_dagrun_data_interval_start": "2025-01-01T00:00:00",
+                "next_dagrun_data_interval_end": "2025-01-01T00:00:00",
+                "next_dagrun_run_after": "2025-01-01T00:00:00",
+            }
+        ]
 
     def test_next_execution_no_schedule(self, api_client_maker):
         api_client = api_client_maker(

Reply via email to