【问题标题】:Airflow replacing single quotes by None on PythonOperator气流在 PythonOperator 上用 None 替换单引号
【发布时间】:2022-07-14 03:10:52
【问题描述】:

在开发一些有关气流的代码时,我看到我的所有 PythonOperator 任务参数在传递给 python_callable 时都被替换为“无”(单引号)。

为了重现,使用以下函数(即 python_callable)

def print_something(something):
    print('Something: ', something)

然后是以下 DAG 和任务:

with DAG(
    dag_id='print_test',
    tags=['Test'],
    start_date=days_ago(1),
    schedule_interval=None,
    default_args={'owner': 'rand'},
    catchup=False,
    render_template_as_native_obj=True,
) as dag:

    print_task = PythonOperator(
        task_id=f'task_print_test',
        dag=dag,
        python_callable=print_something,
        op_kwargs={'something': {'test':''}}
    )

print_task

当我转到任务执行日志时:

[2022-07-13, 12:04:14 -03] {logging_mixin.py:115} INFO - Something:  {'test': None}

因此,气流实际上正在替换 None 值的单引号。

有什么办法可以防止这种情况发生吗?

【问题讨论】:

    标签: python airflow


    【解决方案1】:

    是的,有。删除此 dag 配置:

    render_template_as_native_obj=True
    

    这会导致你的 dag 用 python 对象替换某些东西(参数和其他)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      相关资源
      最近更新 更多