Airflow 未定义任务实例

Airflow 未定义任务实例,airflow,apache-airflow-xcom,Airflow,Apache Airflow Xcom,我有一个传递给xcom的对象,我想从操作符读取它 这是我的接线员: load_csv = GCSToBigQueryOperator( task_id='gcs_to_bigquery', bucket='test', source_objects=['{{ execution_date.strftime("%Y-%m") }}'], providers=True, destination_project_dataset_table=f

我有一个传递给xcom的对象,我想从操作符读取它

这是我的接线员:

load_csv = GCSToBigQueryOperator(
    task_id='gcs_to_bigquery',
    bucket='test',
    source_objects=['{{ execution_date.strftime("%Y-%m") }}'],
    providers=True,
    destination_project_dataset_table=f'{stg_dataset_name}' + '.' + '{{ execution_date.strftime("%Y_%m") }}',
    schema_fields={{ti.xcom_pull(task_ids='print_the_context')}},
    write_disposition='WRITE_TRUNCATE',
    provide_context=True,
    dag=dag)
我想将值从xcom传递到
schema\u字段
变量

我正试图使用以下模板访问该对象
{{ti.xcom\u pull(task\u id='print\u the_context')}
,但我有
它没有定义


这里出了什么问题?

不幸的是,目前还不可能做到这一点

  • 为了能够在
    运算符
    参数中使用,必须在运算符的源代码中定义相应的字段

  • 但在这里的来源,我看到了

因此,您不能通过XCOM模板为
schema\u字段提供值


也就是说,虽然我不知道的内部,我可以看到2种可能的解决方案

  • (直截了当)改用

  • 您可以尝试将其子类化,并在
    template\u字段中包含
    schema\u字段


有趣的读物

template_fields = ('bucket', 'source_objects',
                    'schema_object', 'destination_project_dataset_table')
:param schema_object: If set, a GCS object path pointing to a .json file that
     contains the schema for the table. (templated)
     Parameter must be defined if 'schema_fields' is null and autodetect is False.
 :type schema_object: str