ashb commented on a change in pull request #8805:
URL: https://github.com/apache/airflow/pull/8805#discussion_r425008181
##########
File path: airflow/models/baseoperator.py
##########
@@ -634,6 +650,43 @@ def deps(self) -> Set[BaseTIDep]:
NotPreviouslySkippedDep(),
}
+ def _set_xcomargs_dependencies(self) -> None:
+ """
+ Resolves upstream dependencies of a task. In this way passing an
``XComArg``
+ as value for a template field will result in creating upstream
relation between
+ two tasks.
+
+ **Example**: ::
+
+ with DAG(...):
+ generate_content =
GenerateContentOperator(task_id="generate_content")
+ send_email = EmailOperator(...,
html_content=generate_content.output)
+
+ # This is equivalent to
+ with DAG(...):
+ generate_content =
GenerateContentOperator(task_id="generate_content")
+ send_email = EmailOperator(
+ ..., html_content="{{
task_instance.xcom_pull('generate_content') }}"
+ )
+ generate_content >> send_email
+
+ """
+ from airflow.models.xcom_arg import XComArg
+
+ def apply_set_upstream(arg: Any):
+ if isinstance(arg, XComArg):
+ self.set_upstream(arg.operator)
+ elif isinstance(arg, (tuple, set, list)):
+ for elem in arg:
+ apply_set_upstream(elem)
+ elif isinstance(arg, dict):
Review comment:
https://github.com/apache/airflow/commit/d567f9ab8d5fdd6d18509fd8d623b26795eca25c
Example of such a class from the docs/changelog:
```python
class MyDataReader:
template_fields = ['path']
def __init__(self, my_path):
self.path = my_path
# [additional code here...]
t = PythonOperator(
task_id='transform_data',
python_callable=transform_data
op_args=[
MyDataReader('/tmp/{{ ds }}/my_file')
],
dag=dag)
```
----------------------------------------------------------------
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]