srchilukoori opened a new issue, #65725:
URL: https://github.com/apache/airflow/issues/65725

   ## Airflow CTL Version
   
   0.1.4rc2 (latest stable)
   
   ## Airflow CTL Command
   
   `airflowctl dagrun list`
   
   ## Keyring Backend / Version
   
   Keyring Backend/Headless
   
   ## Auth Type
   
   Token
   
   ## What is the current behaviour?
   
   `airflowctl dagrun list` fails unless **both** `--state` and `--limit` are 
passed explicitly. Two separate errors surface depending on which flag is 
missing:
   
   **Bug 1 — missing `--state` sends literal `"None"` to the API**
   
   Any invocation without `--state` crashes:
   
   ```
   $ airflowctl dagrun list
   Server error: Invalid value for state. Valid values are queued, running, 
success, failed
   
   $ airflowctl dagrun list --limit 5
   Server error: Invalid value for state. Valid values are queued, running, 
success, failed
   
   $ airflowctl dagrun list --dag-id my_dag
   Server error: Invalid value for state. Valid values are queued, running, 
success, failed
   ```
   
   Root cause: `DagRunOperations.list()` in `operations.py` declares `state: 
str` (required, no default). The CLI framework passes `None` when `--state` is 
omitted. Line 630 evaluates `str(None)` → `"None"` → sent to the API, which 
rejects it.
   
   **Bug 2 — missing `--limit` sends an empty string to the API**
   
   Any invocation with `--state` but without `--limit` crashes:
   
   ```
   $ airflowctl dagrun list --state running
   Server error: Input should be a valid integer, unable to parse string as an 
integer (loc: query.limit, input: '')
   
   $ airflowctl dagrun list --state queued
   Server error: Input should be a valid integer, unable to parse string as an 
integer (loc: query.limit, input: '')
   ```
   
   Root cause: Same pattern — `limit: int` is declared with no default. The CLI 
framework passes `None`; httpx encodes `None` as an empty string in the query, 
which fails FastAPI's integer validation.
   
   **Workaround:** Both `--state` and `--limit` must be provided:
   
   ```bash
   airflowctl dagrun list --state running --limit 100
   ```
   
   **Test matrix:**
   
   | Command | Result |
   |---------|--------|
   | `dagrun list` | ❌ state error |
   | `dagrun list --limit 5` | ❌ state error |
   | `dagrun list --dag-id <id>` | ❌ state error |
   | `dagrun list --state running` | ❌ limit error |
   | `dagrun list --state queued` | ❌ limit error |
   | `dagrun list --state running --limit 10` | ✅ works |
   | `dagrun list --state failed --limit 3` | ✅ works |
   
   ## What is the expected results?
   
   Both `--state` and `--limit` should be optional:
   - Omitting `--state` should return dag runs for all states.
   - Omitting `--limit` should use a sensible default (e.g. 100) or the server 
default.
   
   ## Anything else?
   
   **Proposed fix in `airflowctl/api/operations.py`:**
   
   ```python
   # Before
   def list(
       self,
       state: str,
       limit: int,
       ...
   ):
       params: dict[str, Any] = {
           "state": str(state),
           "limit": limit,
       }
   
   # After
   def list(
       self,
       state: str | None = None,
       limit: int | None = None,
       ...
   ):
       params: dict[str, Any] = {}
       if state is not None:
           params["state"] = state
       if limit is not None:
           params["limit"] = limit
   ```
   
   **Environment:** Breeze (Docker), Python 3.10, SQLite backend, 
`httpx==0.28.1`.
   
   > Generated with assistance from Claude (Anthropic). All commands run and 
verified manually against a live Breeze environment.
   
   ## Are you willing to submit a PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ## Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to