Passing a jinja template in TriggerDagRunOperator conf raises json.decoder.JSONDecodeError
See original GitHub issueApache Airflow version:2.0.1
Environment:
- OS (e.g. from /etc/os-release): Ubuntu
What happened: When having a PythonOperator that returns xcom parameters to a TriggerDagRunOperator like in this non-working example:
def conditionally_trigger(spider):
is_ok = db.query()
if is_ok:
payload = {
"foo": "foo",
"bar": "bar",
}
return payload
else:
raise AirflowSkipException
is_job_ok_to_trigger = PythonOperator(
task_id='task1',
python_callable=conditionally_trigger,
dag=dag,
do_xcom_push=True
)
trigger_another_dag= TriggerDagRunOperator(
task_id='trigger_another_dag',
trigger_dag_id='another_dag',
dag=dag,
conf="{{ ti.xcom_pull(task_ids='task1', key='return_value') }}",
)
is_job_ok_to_trigger >> trigger_another_dag
With the first task returning this xcom:
In the second task we fail with this error message:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 1112, in _run_raw_task
self._prepare_and_execute_task_with_callbacks(context, task)
File "/usr/local/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 1285, in _prepare_and_execute_task_with_callbacks
result = self._execute_task(context, task_copy)
File "/usr/local/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 1315, in _execute_task
result = task_copy.execute(context=context)
File "/usr/local/lib/python3.7/site-packages/airflow/operators/trigger_dagrun.py", line 135, in execute
replace_microseconds=False,
File "/usr/local/lib/python3.7/site-packages/airflow/api/common/experimental/trigger_dag.py", line 123, in trigger_dag
replace_microseconds=replace_microseconds,
File "/usr/local/lib/python3.7/site-packages/airflow/api/common/experimental/trigger_dag.py", line 78, in _trigger_dag
run_conf = conf if isinstance(conf, dict) else json.loads(conf)
File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.7/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
with a rendered template of conf being:
What you expected to happen: We should be able to forward a dict like string from an upstream task to TriggerDagRunOperator conf template field which is then converted to json.
It might be related to https://github.com/apache/airflow/issues/14619
How to reproduce it:
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from airflow.operators.trigger_dagrun import TriggerDagRunOperator
dag = DAG('foo', schedule_interval='@daily')
def conditionally_trigger():
payload = {
"foo": "foo",
"bar": "bar",
}
return payload
is_job_ok_to_trigger = PythonOperator(
task_id='task1',
python_callable=conditionally_trigger,
dag=dag,
do_xcom_push=True
)
trigger_another_dag = TriggerDagRunOperator(
task_id='trigger_another_dag',
trigger_dag_id='another_dag',
dag=dag,
conf="{{ ti.xcom_pull(task_ids='task1', key='return_value') }}",
)
is_job_ok_to_trigger >> trigger_another_dag
Anything else we need to know:
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
[GitHub] [airflow] boring-cyborg[bot] commented on issue #14623 ...
[GitHub] [airflow] boring-cyborg[bot] commented on issue #14623: Passing a jinja template in TriggerDagRunOperator conf raises json.decoder.JSONDecodeError.
Read more >JavaScript raises SyntaxError with data rendered in Jinja ...
The problem is that your server returns not JSON, but rendered HTML, which escapes some of the symbols with & notation. Instead of...
Read more >Python JSONDecodeError Explanation and Solution | CK
A Python JSONDecodeError indicates there is an issue with the way in which your JSON data is formatted. For example, your JSON data...
Read more >Template Designer Documentation - Jinja
A template contains variables and/or expressions, which get replaced with values when a template is rendered; and tags, which control the logic of...
Read more >Expecting value: line 1 column 1 (char 0) | JSONDecodeError
json. decoder. JSONDecodeError : Expecting value: line 1 column 1 (char 0)In this video we will be discusing various causes leading to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be solved by https://github.com/apache/airflow/pull/14603
Here is workaround: https://github.com/apache/airflow/issues/11983