fpopic
fpopic

Reputation: 1808

Airflow jinja2 templated json file

I am using Airflow 1.10.1 with Python 3.5 and let's say I extended BaseOperator operator and added .json extension to template_ext

template_ext = ('.json',)

and then I provide a path to the .json template file containing macro placeholders

{
  "kind": "dfareporting#report",
  "name": "{{ params.cm_report_name }}"
}

which has placeholder for params parameter that is passed to all dag operators via default_args.

args = {
    # ...
    'params': {
        'cm_report_name': "AAAA"
    }
}

But for some reason my macro doesn't get substituted with "AAAA".

I tried to copy/paste pattern that bigquery_operator.py is using for .sql files.

Here is the full code of the operator: https://gist.github.com/fpopic/64455b8d24acc6a7d3e6d73392b20c9f#file-cm_report_find_update_operator-py-L15

Upvotes: 0

Views: 995

Answers (1)

Breathe
Breathe

Reputation: 724

You are missing the "template_fields" parameter, like a follow:

template_fields = ('sql', 'destination_dataset_table', 'labels')
template_ext = ('.sql', )

Upvotes: 1

Related Questions