Skip to content

Commit

Permalink
Fix PythonVirtualenvOperator templated_fields
Browse files Browse the repository at this point in the history
The `PythonVirtualenvOperator` templated_fields override `PythonOperator` templated_fields which caused functionality not to work as expected.
fixes: apache#23557
  • Loading branch information
eladkal committed May 7, 2022
1 parent efed15b commit f274568
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion airflow/operators/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,13 @@ class PythonVirtualenvOperator(PythonOperator):
processing templated fields, for examples ``['.sql', '.hql']``
"""

template_fields: Sequence[str] = ('requirements',)
template_fields: Sequence[str] = tuple(
{
'requirements',
}
| set(PythonOperator.template_fields)
)

template_ext: Sequence[str] = ('.txt',)
BASE_SERIALIZABLE_CONTEXT_KEYS = {
'ds',
Expand Down
3 changes: 3 additions & 0 deletions tests/operators/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ def _run_as_operator(self, fn, python_version=sys.version_info[0], **kwargs):
task.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE)
return task

def test_template_fields(self):
assert set(PythonOperator.template_fields).issubset(PythonVirtualenvOperator.template_fields)

def test_add_dill(self):
def f():
"""Ensure dill is correctly installed."""
Expand Down

0 comments on commit f274568

Please sign in to comment.