Skip to content

Commit

Permalink
[AIRFLOW-597] Check if content is None, not false-equivalent
Browse files Browse the repository at this point in the history
Closes apache#1856 from gwax/non_boolean_templates
  • Loading branch information
George Leslie-Waksman authored and r39132 committed Oct 27, 2016
1 parent 46236fa commit 2f26126
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions airflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2164,8 +2164,9 @@ def resolve_template_files(self):
# Getting the content of files for template_field / template_ext
for attr in self.template_fields:
content = getattr(self, attr)
if (content and isinstance(content, six.string_types) and
any([content.endswith(ext) for ext in self.template_ext])):
if content is not None and \
isinstance(content, six.string_types) and \
any([content.endswith(ext) for ext in self.template_ext]):
env = self.dag.get_template_env()
try:
setattr(self, attr, env.loader.get_source(env, content)[0])
Expand Down
16 changes: 16 additions & 0 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,22 @@ def verify_templated_field(context):
t.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True)
assert val['success']

def test_template_non_bool(self):
"""
Test templates can handle objects with no sense of truthiness
"""
class NonBoolObject(object):
def __len__(self):
return NotImplemented
def __bool__(self):
return NotImplemented

t = OperatorSubclass(
task_id='test_bad_template_obj',
some_templated_field=NonBoolObject(),
dag=self.dag)
t.resolve_template_files()

def test_import_examples(self):
self.assertEqual(len(self.dagbag.dags), NUM_EXAMPLE_DAGS)

Expand Down

0 comments on commit 2f26126

Please sign in to comment.