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

   ### Under which category would you file this issue?
   
   Airflow Core
   
   ### Apache Airflow version
   
   3.2.0
   
   ### What happened and how to reproduce it?
   
   The state parameter on 
`DagRun.get_task_instances`[[code](https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/models/dagrun.py#L916-L920)]
 and 
`DagRun.fetch_task_instances`[[code](https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/models/dagrun.py#L834-L840)]
 is annotated:
   ```
   state: Iterable[TaskInstanceState | None] | None = None
   ```
   but the implementation explicitly handles a single state value via an 
`isinstance(state, 
str)`[[code](https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/models/dagrun.py#L853-L854)]
 short-circuit:
   ```
     if isinstance(state, str):
         tis = tis.where(TI.state == state)
     else:
         ...
         tis = tis.where(TI.state.in_(state))
   ```
   
   Because `TaskInstanceState(str, Enum)` inherits from `str`, calling 
`dagrun.get_task_instances(state=TaskInstanceState.FAILED)` works at runtime 
and takes the `==` branch, but mypy/pyright flag it, and the docs/signature 
don't communicate that it's allowed.
   
   The single-state code path is clearly deliberate, so the annotation should 
reflect it.
   
   ### What you think should happen instead?
   
   I propose to widen the annotation to `TaskInstanceState | 
Iterable[TaskInstanceState | None] | None` on both methods.
   
   ### Operating System
   
   _No response_
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Apache Airflow Provider(s)
   
   _No response_
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Official Helm Chart version
   
   1.21.0 (latest released)
   
   ### Kubernetes Version
   
   _No response_
   
   ### Helm Chart configuration
   
   _No response_
   
   ### Docker Image customizations
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit 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