-
-
Notifications
You must be signed in to change notification settings - Fork 747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pass without exception if jinja parameter isn't found #6101
base: master
Are you sure you want to change the base?
Changes from 5 commits
09e968a
fd74ef5
06fc936
9f46039
40f7de3
8f26137
08fc039
dc179aa
313437f
65d5685
a2f81b7
6aac6ad
3bd25ab
2e469fd
f4670f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,17 +170,80 @@ def _process_defaults(G, schemas): | |
_process(G, name, value.get("default")) | ||
|
||
|
||
def _check_any_bad(G, nodes, check_any_bad=None, tracked_parents=None): | ||
""" | ||
:param G: nx.DiGraph | ||
:param nodes: list[dict] | ||
:param check_any_bad: list[boolean] | ||
:param tracked_parents: list[str] | ||
""" | ||
if tracked_parents is None: | ||
tracked_parents = [] | ||
if check_any_bad is None: | ||
check_any_bad = [] | ||
for name in nodes: | ||
if "value" not in G.nodes[name] and "template" not in G.nodes[name]: | ||
# this is a string not a jinja template; embedded {{sometext}} | ||
check_any_bad.append(False) | ||
else: | ||
check_any_bad.append(True) | ||
children = [i for i in G.predecessors(name)] | ||
if name not in tracked_parents: | ||
tracked_parents.extend(nodes) | ||
_check_any_bad(G, children, check_any_bad, tracked_parents) | ||
guzzijones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return check_any_bad | ||
|
||
|
||
def _remove_bad(g_copy, parent, nodes, tracked_parents=None): | ||
""" | ||
:param G: nx.DiGraph | ||
:param nodes: str | ||
:param check_any_bad: list[str] | ||
:param tracked_parents: list[str] | ||
""" | ||
|
||
if tracked_parents is None: | ||
tracked_parents = [parent] | ||
else: | ||
tracked_parents.append(parent) | ||
for i in nodes: | ||
g_copy.nodes[parent]["value"] = g_copy.nodes[parent].pop("template") | ||
guzzijones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if i in g_copy.nodes: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
children = [i for i in g_copy.predecessors(i)] | ||
if children: | ||
if i not in tracked_parents: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see anywhere that adds the children to tracked_parents while walking the tree which means the |
||
_remove_bad(g_copy, i, children) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this line need to pass in |
||
# remove template for neighbors; this isn't actually a variable | ||
# it is a value | ||
# remove template attr if it exists on parent | ||
# remove edges | ||
g_copy.remove_edge(i, parent) | ||
# remove node from graph | ||
g_copy.remove_node(i) | ||
|
||
|
||
def _validate(G): | ||
""" | ||
Validates dependency graph to ensure it has no missing or cyclic dependencies | ||
""" | ||
g_copy = G.copy() | ||
for name in G.nodes: | ||
guzzijones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if "value" not in G.nodes[name] and "template" not in G.nodes[name]: | ||
msg = 'Dependency unsatisfied in variable "%s"' % name | ||
raise ParamException(msg) | ||
|
||
if not nx.is_directed_acyclic_graph(G): | ||
graph_cycles = nx.simple_cycles(G) | ||
children = [i for i in G.predecessors(name)] | ||
if len(children) > 0: | ||
# has children | ||
check_all = _check_any_bad(G, children) | ||
# check if all are FALSE | ||
if not any(check_all): | ||
# this is a string or object with embedded jinja string that | ||
# doesn't exist as a parameter and not a jinja template; embedded {{sometext}} | ||
_remove_bad(g_copy, name, children) | ||
elif True in check_all and False in check_all: | ||
msg = 'Dependency unsatisfied in variable "%s"' % name | ||
# one of the parameters exists but not all | ||
raise ParamException(msg) | ||
|
||
if not nx.is_directed_acyclic_graph(g_copy): | ||
graph_cycles = nx.simple_cycles(g_copy) | ||
|
||
variable_names = [] | ||
for cycle in graph_cycles: | ||
|
@@ -197,6 +260,7 @@ def _validate(G): | |
"referencing itself" % (variable_names) | ||
) | ||
raise ParamException(msg) | ||
return g_copy | ||
|
||
|
||
def _render(node, render_context): | ||
|
@@ -276,7 +340,6 @@ def _cast_params_from(params, context, schemas): | |
# value is a template, it is rendered and added to the live params before this validation. | ||
for schema in schemas: | ||
for param_name, param_details in schema.items(): | ||
|
||
# Skip if the parameter have immutable set to true in schema | ||
if param_details.get("immutable"): | ||
continue | ||
|
@@ -336,8 +399,7 @@ def render_live_params( | |
|
||
[_process(G, name, value) for name, value in six.iteritems(params)] | ||
_process_defaults(G, [action_parameters, runner_parameters]) | ||
_validate(G) | ||
|
||
G = _validate(G) | ||
context = _resolve_dependencies(G) | ||
live_params = _cast_params_from( | ||
params, context, [action_parameters, runner_parameters] | ||
|
@@ -359,7 +421,7 @@ def render_final_params(runner_parameters, action_parameters, params, action_con | |
# by that point, all params should already be resolved so any template should be treated value | ||
[G.add_node(name, value=value) for name, value in six.iteritems(params)] | ||
_process_defaults(G, [action_parameters, runner_parameters]) | ||
_validate(G) | ||
G = _validate(G) | ||
|
||
context = _resolve_dependencies(G) | ||
context = _cast_params_from( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With extend, only the first child gets checked, not any of the others. Is that intentional? If so, it's not clear why we want to do that.