Skip to content

Improve error message when template fields contain invalid entries #12876

Description

@ecerulm

** Description **

When a new operator is defined there are some issues with template_fields that produces somewhat misleading error messages

  • template_fields = ('myfield'), which of course is incorrect because that is not a tuple, you need to use ('myfield',) or ['myfield']
  • template_field = ['field_with_a_typo']

As a I said both gives errors (at different stages) but the errors are a bit cryptic

For example:

[2020-12-07 09:50:45,088] {taskinstance.py:1150} ERROR - 'SFTPToS3Operator2' object has no attribute 's3_key'
Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 965, in _run_raw_task
    self.render_templates(context=context)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1424, in render_templates
    self.task.render_template_fields(context)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/baseoperator.py", line 719, in render_template_fields
    self._do_render_template_fields(self, self.template_fields, context, jinja_env, set())
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/baseoperator.py", line 724, in _do_render_template_fields
    content = getattr(parent, attr_name)
AttributeError: 'SFTPToS3Operator2' object has no attribute 's3_key'

where there is no mention that this is related to templated_fields

Use case / motivation

In order to have a better experience developing plugins I would like

  • A warning / error if a str is used for template_fields = 'myfield'. It's very unlikely that anyone want to use myfield as sequence ['m','y', 'f','i','e','l','d'].
  • A more specific error message in _run_raw_task if template_fields contains attributes not present.

Description

Use case / motivation

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions