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

   ### Apache Airflow version
   
   2.6.0
   
   ### What happened
   
   
当我在task里设置max_active_tis_per_dagrun=1后,并发运行dag时,per_dagrun并没有限制到每个dagrun,而是在dag级别限制并发。
   queued状态的task日志显示:`dependency 'Task Concurrency' FAILED: The max task 
concurrency per run has been reached.`
   
   
   ### What you think should happen instead
   
   
查找到日志产生的函数是:airflow/ti_deps/deps/task_concurrency_dep.py中TaskConcurrencyDep._get_dep_statuses
   
[https://github.com/apache/airflow/blob/b8f73768ec13f8d4cc1605cca3fa93be6caac473/airflow/models/taskinstance.py#L2551](url)
   代码中调用的ti.get_num_running_task_instances(session, same_dagrun=True)这个方法中
   ```python
          num_running_task_instances_query = session.query(func.count()).filter(
               TaskInstance.dag_id == self.dag_id,
               TaskInstance.task_id == self.task_id,
               TaskInstance.state == State.RUNNING,
           ) 
           if same_dagrun:
               num_running_task_instances_query.filter(TaskInstance.run_id == 
self.run_id)
   ```
   
   代码`num_running_task_instances_query.filter(TaskInstance.run_id == 
self.run_id)`在执行sql时,并未真正将`TaskInstance.run_id == self.run_id`写入到sql中
   
   filter:sqlalchemy/orm/query.py的Query.filter方法
   ```python
   @_generative
       @_assertions(_no_statement_condition, _no_limit_offset)
       def filter(self, *criterion):
   ```
   这个filter不支持链式调用,因为它每次都会返回一个新的object
   
   
   
   
   ### How to reproduce
   
   
[https://github.com/apache/airflow/blob/b8f73768ec13f8d4cc1605cca3fa93be6caac473/airflow/models/taskinstance.py#L2551](url)
   代码:
   ```python
   if same_dagrun:
       num_running_task_instances_query.filter(TaskInstance.run_id == 
self.run_id)
   ```
   
   应该改为:
   ```python
   if same_dagrun:
       num_running_task_instances_query = 
num_running_task_instances_query.filter(TaskInstance.run_id == self.run_id)
   ```
   
   ### Operating System
   
   centos 6.5
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Virtualenv installation
   
   ### Deployment details
   
   _No response_
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] 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