Skip to content

Commit

Permalink
pyyaml 4.1 raised an error during testing of parsing of 'yaml'-format…
Browse files Browse the repository at this point in the history
… templates

Our output documents support a 'yaml' experimental template format. In this format, we recursively walk the data structure and replace string values by evaluating them as their own output document templates. However, when we run documents in the PARSE_ONLY mode for validating modules, the inner document templates return junk values if validation passes, and if these junk values are not safe for YAML output (i.e. not basic data types), pyyaml 4.1 raises an exception.

The fix is to not render the substituted data structure back to YAML when the caller is just testing that e.g. Jinja2 syntax is correct.
  • Loading branch information
JoshData committed Jun 28, 2018
1 parent 1de29c4 commit 94d646e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions guidedmodules/module_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ def walk(value, path):
# Render strings within the data structure.
value = walk(template_body, [])

# If we're just testing parsing the template, return
# any output now. Since the inner templates may have
# returned a value of any type, we can't serialize back to
# JSON --- pyyaml's safe dumper will raise an error if
# it gets a non-safe value type.
if output_format == "PARSE_ONLY":
return value

# Render to JSON or YAML depending on what was specified on the
# template.
if template_format == "json":
Expand Down

0 comments on commit 94d646e

Please sign in to comment.