8

使用 PapermillOperator 运行气流作业时,dag 执行失败。

我在将参数传递给 PapermillOperator 时遇到问题。

我打开了papermill_operator.py (packages/airflow/operators/papermill_operator.py) 并硬编码了一行来指定 paparameters

def execute(self, context):
        for i in range(len(self.inlets)):
            pm.execute_notebook(self.inlets[i].location, 
                                self.outlets[i].location,
                                parameters = dict(msgs="hello")
                                progress_bar=False, report_mode=True)

然后它的工作

而原始代码是

def execute(self, context):
        for i in range(len(self.inlets)):
            pm.execute_notebook(self.inlets[i].location, 
                                self.outlets[i].location,
                                parameters=self.inlets[i].parameters,
                                progress_bar=False, report_mode=True)

尝试了另一个解决方案 https://github.com/nteract/papermill/issues/324#issuecomment-472446375 它工作正常

我的 DAG 代码是

import airflow

from airflow.models import DAG
from airflow.operators.papermill_operator import PapermillOperator

from datetime import timedelta

args = {
    'owner': 'Airflow',
    'start_date': airflow.utils.dates.days_ago(2),

}

dag = DAG(
    dag_id='9', default_args=args,
    schedule_interval='@once',
    dagrun_timeout=timedelta(minutes=10))

run_this = PapermillOperator(
    task_id="1",
    dag=dag,
    input_nb="/home/exa00112/abc.ipynb",
    output_nb="/home/exa00112/umesh.ipynb",
    parameters = dict("msgs" = "hello")
)

run_this

[2019-09-10 20:36:48,806] {logging_mixin.py:95} INFO - [2019-09-10 > > > 20:36:48,806] {datasets.py:62} INFO - 参数 [2019-09 -10 20:36:48,806] { init .py:1580} 错误 - 无法编译非 > 模板节点 Traceback(最近一次调用):文件“/usr/local/lib/python3.5/dist-packages/气流/模型/ init .py”,第 1441 行,在 _run_raw_task 结果 = task_copy.execute(context=context) 文件“/usr/local/lib/python3.5/dist-packages/airflow/operators/papermill_operator.py”中,第 63 行,在执行参数=self.inlets[i].parameters,文件“/usr/local/lib/python3.5/dist-packages/airflow/lineage/datasets.py”,第 66 行,在getattr 返回 env.from_string(self._data.get(attr)).render(**self.context) 文件 "/home/exa00112/.local/lib/python3.5/site-packages/jinja2/environment.py",第 880 行,在 from_string 返回 cls.from_code(self, self.compile(source), globals, None) 文件“/home/exa00112/.local/lib/python3.5/site-packages/jinja2/environment.py”,第 581 行,在 compile defer_init=defer_init) 文件 "/home/exa00112/.local/lib/python3.5/site-packages/jinja2/environment.py",第 543 行,在 _generate optimization=self.optimized) 文件 "/ home/exa00112/.local/lib/python3.5/site-packages/jinja2/compiler.py",第 78 行,在生成中引发 TypeError('Can\'t compile non template nodes') TypeError: Can't compile non模板节点 [2019-09-10 20:36:48,808] { init .py:1611} 信息 - 将任务标记为失败。

4

1 回答 1

1

似乎是 Papermill Operator 向 Papermill 传递无效参数数据结构(当 papermill 查找 dict 时传递字符串参数 dict)到的已知问题

https://issues.apache.org/jira/browse/AIRFLOW-5774

不确定何时修复,因为它看起来是重复的问题,很难追踪

于 2019-10-30T22:22:33.127 回答