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

shahar1 pushed a commit to branch airflow-ctl/v0-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/airflow-ctl/v0-1-test by this 
push:
     new c53a1046e17 [airflow-ctl/v0-1-test] Fix enum names and non-ISO dates 
in airflowctl dags output (#76354) (#76574)
c53a1046e17 is described below

commit c53a1046e1776122d37e68cf31efc9ad40a50709
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Nov 6 06:27:52 2026 +0000

    [airflow-ctl/v0-1-test] Fix enum names and non-ISO dates in airflowctl dags 
output (#76354) (#76574)
    
    * [airflow-ctl/v0-1-test] 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.
    (cherry picked from commit 3204b6ebebbd83d69e1203a52a78e85692d2cf5f)
    
    Co-authored-by: Y-C <[email protected]>
    
    * Test the enum output fix against the field this branch has
    
    The cherry-picked test asserts on `scheduling_state`, which `DAGResponse`
    does not have on this branch, so it raised KeyError. `allowed_run_types`
    is the enum field that `pause` and `unpause` print here, and it printed
    "DagRunType.MANUAL" before this fix.
    
    Claude-Session: https://claude.ai/code/session_01BVx6g7kMcPenQEPwEZbPQJ
    
    ---------
    
    Co-authored-by: Y-C <[email protected]>
    Co-authored-by: Shahar Epstein <[email protected]>
---
 .../src/airflowctl/ctl/commands/dag_command.py     |  5 ++--
 .../airflow_ctl/ctl/commands/test_dag_command.py   | 31 ++++++++++++++--------
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/airflow-ctl/src/airflowctl/ctl/commands/dag_command.py 
b/airflow-ctl/src/airflowctl/ctl/commands/dag_command.py
index 3160277fad3..0027a36e36a 100644
--- a/airflow-ctl/src/airflowctl/ctl/commands/dag_command.py
+++ b/airflow-ctl/src/airflowctl/ctl/commands/dag_command.py
@@ -51,7 +51,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)
@@ -101,7 +101,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 6153db29677..cbc11fd44bc 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
@@ -24,7 +24,7 @@ import httpx
 import pytest
 
 from airflowctl.api.client import ClientKind
-from airflowctl.api.datamodels.generated import DAGResponse
+from airflowctl.api.datamodels.generated import DAGResponse, DagRunType
 from airflowctl.api.operations import ServerResponseError
 from airflowctl.ctl import cli_parser
 from airflowctl.ctl.commands import dag_command
@@ -47,6 +47,7 @@ class TestDagCommands:
     dag_response_paused = DAGResponse(
         dag_id=dag_id,
         dag_display_name=dag_display_name,
+        allowed_run_types=[DagRunType.MANUAL],
         is_paused=False,
         last_parsed_time=datetime.datetime(2024, 12, 31, 23, 59, 59),
         last_expired=datetime.datetime(2025, 1, 1, 0, 0, 0),
@@ -77,6 +78,7 @@ class TestDagCommands:
     dag_response_unpaused = DAGResponse(
         dag_id=dag_id,
         dag_display_name=dag_display_name,
+        allowed_run_types=[DagRunType.MANUAL],
         is_paused=True,
         last_parsed_time=datetime.datetime(2024, 12, 31, 23, 59, 59),
         last_expired=datetime.datetime(2025, 1, 1, 0, 0, 0),
@@ -198,10 +200,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,
         )
@@ -210,7 +212,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["allowed_run_types"] == 
response_json["allowed_run_types"] == ["manual"]
+        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:"
         )
@@ -234,21 +239,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