You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "henry3260 (via GitHub)" <gi...@apache.org> on 2026/02/06 11:01:27 UTC

[PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

henry3260 opened a new pull request, #61525:
URL: https://github.com/apache/airflow/pull/61525

   Make dag_id parameter optional in DagRunOperations.list() and default to ~ for querying all DAGs. Also make other filter parameters (state, limit, start_date, end_date) optional for better CLI flexibility.
   
   closes: #ISSUE
   
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, please
   change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
   -->
   
   - [ ] Yes (please specify the tool below)
   
   <!--
   Generated-by: [Tool Name] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 closed pull request #61525: fix(airflowctl): allow listing dag runs without specifying dag_id
URL: https://github.com/apache/airflow/pull/61525


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #61525:
URL: https://github.com/apache/airflow/pull/61525#discussion_r2774103828


##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -554,20 +554,36 @@ def get(self, dag_id: str, dag_run_id: str) -> DAGRunResponse | ServerResponseEr
 
     def list(
         self,
-        dag_id: str,
-        start_date: datetime.datetime,
-        end_date: datetime.datetime,
-        state: str,
-        limit: int,
+        start_date: datetime.datetime | None = None,
+        end_date: datetime.datetime | None = None,
+        state: str | None = None,
+        limit: int | None = None,
+        dag_id: str | None = None,
     ) -> DAGRunCollectionResponse | ServerResponseError:
-        """List all dag runs."""
-        params = {
-            "start_date": start_date,
-            "end_date": end_date,
-            "state": state,
-            "limit": limit,
-            "dag_id": dag_id,
-        }
+        """
+        List all dag runs.
+
+        Args:
+            start_date: Filter dag runs by start date (optional)
+            end_date: Filter dag runs by end date (optional)
+            state: Filter dag runs by state (optional)
+            limit: Limit the number of results (optional)
+            dag_id: The DAG ID to filter by. If None, retrieves dag runs for all DAGs (using "~").
+        """
+        # Use "~" for all DAGs if dag_id is not specified
+        if not dag_id:
+            dag_id = "~"
+
+        params = {}
+        if start_date is not None:
+            params["start_date"] = start_date
+        if end_date is not None:
+            params["end_date"] = end_date
+        if state is not None:
+            params["state"] = state
+        if limit is not None:
+            params["limit"] = limit

Review Comment:
   Could we implement this as -  
   -  
    ```
     if dag_id == None:
               dag_id = "~"
           params = {
               "start_date": start_date,
               "end_date": end_date,
               "state": state,
               "limit": limit,
               "dag_id": dag_id,
           }
   ```
   
   Could you please share your view ? 
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 commented on code in PR #61525:
URL: https://github.com/apache/airflow/pull/61525#discussion_r2805249091


##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -554,20 +554,36 @@ def get(self, dag_id: str, dag_run_id: str) -> DAGRunResponse | ServerResponseEr
 
     def list(
         self,
-        dag_id: str,
-        start_date: datetime.datetime,
-        end_date: datetime.datetime,
-        state: str,
-        limit: int,
+        start_date: datetime.datetime | None = None,
+        end_date: datetime.datetime | None = None,
+        state: str | None = None,

Review Comment:
   > https://github.com/apache/airflow/blob/327201f5f9198ab3d19c1a07b8a39bcd0f61a7c4/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dag_run.py#L79
   > 
   > 
   > Unfortunately, some fields cannot be `None` due to the API side of it. We can follow the same approach as how you set a default variable for them. Could you please double-check with the datamodel? I think some can indeed, such as end_date, but some canno,t such as state
   
   Applied!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 merged PR #61525:
URL: https://github.com/apache/airflow/pull/61525


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on code in PR #61525:
URL: https://github.com/apache/airflow/pull/61525#discussion_r2801588639


##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -554,20 +554,36 @@ def get(self, dag_id: str, dag_run_id: str) -> DAGRunResponse | ServerResponseEr
 
     def list(
         self,
-        dag_id: str,
-        start_date: datetime.datetime,
-        end_date: datetime.datetime,
-        state: str,
-        limit: int,
+        start_date: datetime.datetime | None = None,
+        end_date: datetime.datetime | None = None,
+        state: str | None = None,

Review Comment:
   https://github.com/apache/airflow/blob/327201f5f9198ab3d19c1a07b8a39bcd0f61a7c4/airflow-core/src/airflow/api_fastapi/core_api/datamodels/dag_run.py#L79
   Unfortunately, some fields cannot be `None` due to the API side of it. We can follow the same approach as how you set a default variable for them. Could you please double-check with the datamodel? I think some can indeed, such as end_date, but some canno,t such as state



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on PR #61525:
URL: https://github.com/apache/airflow/pull/61525#issuecomment-3860354812

   `DAGRunState` must be one of the 4 values mentioned here and cannot be None
   https://github.com/apache/airflow/blob/d273931f88e4332e84793f371b1efb8661c92310/airflow-ctl/src/airflowctl/api/datamodels/generated.py#L360
   
   It's just My thought I'd love to hear your thoughts 
   
   cc: @bugraoz93 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

Posted by "Subham-KRLX (via GitHub)" <gi...@apache.org>.
Subham-KRLX commented on PR #61525:
URL: https://github.com/apache/airflow/pull/61525#issuecomment-3861820021

   Nice fix One small suggestion for cli_config.py to make the type parsing a bit more robust Instead of type_name.replace(" | None", "") which relies on exact spacing, you could split by | This handles variations like str|None or extra spaces automatically.
   # Handle Optional types (e.g., "datetime.datetime | None", "str | None")
   base_type = type_name.split("|")[0].strip()
   return base_type in primitive_types


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #61525:
URL: https://github.com/apache/airflow/pull/61525#discussion_r2807149077


##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -554,20 +554,36 @@ def get(self, dag_id: str, dag_run_id: str) -> DAGRunResponse | ServerResponseEr
 
     def list(
         self,
-        dag_id: str,
-        start_date: datetime.datetime,
-        end_date: datetime.datetime,
-        state: str,
-        limit: int,
+        start_date: datetime.datetime | None = None,
+        end_date: datetime.datetime | None = None,
+        state: str | None = None,
+        limit: int | None = None,
+        dag_id: str | None = None,
     ) -> DAGRunCollectionResponse | ServerResponseError:
-        """List all dag runs."""
-        params = {
-            "start_date": start_date,
-            "end_date": end_date,
-            "state": state,
-            "limit": limit,
-            "dag_id": dag_id,
-        }
+        """
+        List all dag runs.
+
+        Args:
+            start_date: Filter dag runs by start date (optional)
+            end_date: Filter dag runs by end date (optional)
+            state: Filter dag runs by state (optional)
+            limit: Limit the number of results (optional)
+            dag_id: The DAG ID to filter by. If None, retrieves dag runs for all DAGs (using "~").
+        """
+        # Use "~" for all DAGs if dag_id is not specified
+        if not dag_id:
+            dag_id = "~"
+
+        params = {}
+        if start_date is not None:
+            params["start_date"] = start_date
+        if end_date is not None:
+            params["end_date"] = end_date
+        if state is not None:
+            params["state"] = state
+        if limit is not None:
+            params["limit"] = limit

Review Comment:
   Yup !! Agreed !!
   
   Thanks !! I meant it in a different way, but I picked up another concept along the way.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(airflowctl): allow listing dag runs without specifying dag_id [airflow]

Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 commented on code in PR #61525:
URL: https://github.com/apache/airflow/pull/61525#discussion_r2774793240


##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -554,20 +554,36 @@ def get(self, dag_id: str, dag_run_id: str) -> DAGRunResponse | ServerResponseEr
 
     def list(
         self,
-        dag_id: str,
-        start_date: datetime.datetime,
-        end_date: datetime.datetime,
-        state: str,
-        limit: int,
+        start_date: datetime.datetime | None = None,
+        end_date: datetime.datetime | None = None,
+        state: str | None = None,
+        limit: int | None = None,
+        dag_id: str | None = None,
     ) -> DAGRunCollectionResponse | ServerResponseError:
-        """List all dag runs."""
-        params = {
-            "start_date": start_date,
-            "end_date": end_date,
-            "state": state,
-            "limit": limit,
-            "dag_id": dag_id,
-        }
+        """
+        List all dag runs.
+
+        Args:
+            start_date: Filter dag runs by start date (optional)
+            end_date: Filter dag runs by end date (optional)
+            state: Filter dag runs by state (optional)
+            limit: Limit the number of results (optional)
+            dag_id: The DAG ID to filter by. If None, retrieves dag runs for all DAGs (using "~").
+        """
+        # Use "~" for all DAGs if dag_id is not specified
+        if not dag_id:
+            dag_id = "~"
+
+        params = {}
+        if start_date is not None:
+            params["start_date"] = start_date
+        if end_date is not None:
+            params["end_date"] = end_date
+        if state is not None:
+            params["state"] = state
+        if limit is not None:
+            params["limit"] = limit

Review Comment:
   > ## Could we implement this as -
   > ```
   >  if dag_id == None:
   >            dag_id = "~"
   >        params = {
   >            "start_date": start_date,
   >            "end_date": end_date,
   >            "state": state,
   >            "limit": limit,
   >            "dag_id": dag_id,
   >        }
   > ```
   > 
   > Could you please share your view ?
   
   Thanks for reviewing! IMO, I think using `if not dag_id:` is more robust, because it also handles empty string `("")` in addition to `None`. In this PR, we allow parameters like `state, limit, start_date, end_date` to be optional . When users don't provide value, they will be `None` and should not be included in the API request.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org