Comment 0 for bug 1711444

Revision history for this message
Bob Haddleton (bob-haddleton) wrote : Nested AdHoc actions do not process all output transformations

When using nested AdHoc Actions that use output transformations, the action result is only being transformed by the output of the action that is being called. Output transformations in nested actions are not processed.

For example:

actions:
  concat_twice:
    base: std.echo
    base-input:
      output: "<% $.s1 %>+<% $.s2 %>"
    input:
      - s1: "a"
      - s2
    output: "<% $ %> and <% $ %>"

  nested_concat:
    base: my_wb.concat_twice
    base-input:
      s1: '{{ _.n1 }}'
      s2: 'bar'
    input:
      - n1: 'foo'
    output:
      nested_concat: '{{ _ }}'

If concat_twice is called, the output is "foo+bar and foo+bar"

So the expected output from nested_concat would be {"nested_concat": "foo+bar and foo+bar"}

But since the output transform of the called action is the only one that is executed, the output transform in the concat_twice action is skipped and the output is:

{"nested_concat": "foo+bar"}

The fix for this is to do the same traversal of nested actions in the _prepare_output() method that is already being done in the _prepare_input() method, except that the order is reversed so that the base action output transform is processed first, and the called action output transform is called last.

    def _prepare_output(self, result):
        # In case of error, we don't transform a result.
        if not result.is_error():
            for action_def in reversed(self.adhoc_action_defs):
                adhoc_action_spec = spec_parser.get_action_spec(action_def.spec)

                transformer = adhoc_action_spec.get_output()

                if transformer is not None:
                    result = ml_actions.Result(
                        data=expr.evaluate_recursively(transformer, result.data),
                        error=result.error
                    )
        return result