houqp commented on a change in pull request #10153:
URL: https://github.com/apache/airflow/pull/10153#discussion_r472502513
##########
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:
it looks like we are still changing the semantic of task_id here. would
it make more sense to use `self.label` to store `
f"{task_group.group_id}.{self.label}"` and leave `task_id` as is?
##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -626,3 +648,59 @@ def from_dict(cls, serialized_obj: dict) ->
'SerializedDAG':
if ver != cls.SERIALIZER_VERSION:
raise ValueError("Unsure how to deserialize version
{!r}".format(ver))
return cls.deserialize_dag(serialized_obj['dag'])
+
+
+class SerializedTaskGroup(TaskGroup, BaseSerialization):
+ """
+ A JSON serializable representation of TaskGroup.
+ """
+ @classmethod
+ def serialize_task_group(cls, task_group: TaskGroup) ->
Optional[Union[Dict[str, Any]]]:
+ """Serializes TaskGroup into a JSON object.
+ """
+ if not task_group:
+ return None
+
+ serialize_group = {}
+ serialize_group["_group_id"] = task_group._group_id # pylint:
disable=protected-access
+
+ serialize_group['children'] = { # type: ignore
+ label: (DAT.OP, child.task_id)
+ if isinstance(child, BaseOperator) else
+ (DAT.TASK_GROUP, SerializedTaskGroup.serialize_task_group(child))
+ for label, child in task_group.children.items()
+ }
+ serialize_group['tooltip'] = task_group.tooltip
+ serialize_group['ui_color'] = task_group.ui_color
+ serialize_group['ui_fgcolor'] = task_group.ui_fgcolor
Review comment:
nitpick, these can be simplified/optimized to:
```suggestion
serialize_group = {
"_group_id": task_group._group_id, # pylint:
disable=protected-access
"tooltip": task_group.tooltip,
"ui_color": task_group.ui_color,
"ui_fgcolor": task_group.ui_fgcolor,
"children": { # type: ignore
label: (DAT.OP, child.task_id)
if isinstance(child, BaseOperator) else
(DAT.TASK_GROUP,
SerializedTaskGroup.serialize_task_group(child))
for label, child in task_group.children.items()
},
}
```
----------------------------------------------------------------
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]