yuqian90 commented on a change in pull request #10153:
URL: https://github.com/apache/airflow/pull/10153#discussion_r478394967
##########
File path: airflow/models/baseoperator.py
##########
@@ -382,7 +389,16 @@ def __init__(
stacklevel=3
)
validate_key(task_id)
- self.task_id = task_id
+ self.label = task_id
+
+ # Prefix task_id with group_id
+ task_group = task_group or TaskGroupContext.get_current_task_group(dag)
+ if task_group:
+ self.task_id = f"{task_group.group_id}.{self.label}" if
task_group.group_id else self.label
Review comment:
Hi @houqp, even without TaskGroup, users cannot define tasks with
conflicting names in the same DAG. So if we simply remove the notion of `label`
in this PR, we can achieve that. That means the label in Graph View will be the
same as `task_id`. And users have to do their own work to maintain unique
`task_id` across the entire DAG, and across TaskGroups.
The same example will look like this. And the `task_id` kept in
`dag.task_dict` and the labels shown on the Graph View both look like this:
```
section_1_task_1
section_1_task_2
section_2_task_1
section_2_task_2
```
```
def create_section(group_id):
task1 = DummyOperator(task_id=f"{group_id}_task_1")
task2 = DummyOperator(task_id=f"{group_id}_task_2")
with DAG(...) as dag:
with TaskGroup("section1") as section1:
create_section(section1.group_id)
with TaskGroup("section2") as section2:
create_section(section2.group_id)
```
How does it sound?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]