StackStorm / st2

StackStorm (aka "IFTTT for Ops") is event-driven automation for auto-remediation, incident responses, troubleshooting, deployments, and more for DevOps and SREs. Includes rules engine, workflow, 160 integration packs with 6000+ actions (see https://exchange.stackstorm.org) and ChatOps. Installer at https://docs.stackstorm.com/install/index.html
https://stackstorm.com/
Apache License 2.0
6.09k stars 747 forks source link

"malformed string" when passing a non-array input from a workflow into an action parameter of type array #4375

Open jeking3 opened 6 years ago

jeking3 commented 6 years ago
SUMMARY

With an action that takes a parameter of type array, I can run the action from the command line and I can even pass a regular string to it, and it seems to figure it out. However if I do the same thing from a workflow (either mistral or orquesta, it doesn't matter, they both fail) and pass a string into an array parameter for an action, things error out badly without a good error message. Improving the error message would be a sufficient remedy; in fact getting the parameter/input field name into the error message would be good too.

ISSUE TYPE
STACKSTORM VERSION

st2 3.0dev (3438b7c), on Python 2.7.6 (also happens on 2.9.0)

OS / ENVIRONMENT / INSTALL METHOD

st2-docker

STEPS TO REPRODUCE

Install the pack I made that demonstrates the issue:

st2 pack install https://github.com/jeking3/st2-issue-badtype.git

Run the action and pass in a string, see that it works even though the input is of type array - this is because the presence of just one argument is still handled as an array:

root@f34287ba9aa8:/# st2 run badtype.take_array value=hello
.
id: 5bb60780668fd406fff4d76f
status: succeeded
parameters:
  value:
  - hello
result:
  exit_code: 0
  result:
  - hello
  stderr: ''
  stdout: ''

Now run the bad_workflow which attempts to feed the same input from a workflow:

    input:
      value: hello

and the result:

root@f34287ba9aa8:/# st2 run badtype.bad_workflow
.
id: 5bb609d5668fd406fff4d781
action.ref: badtype.bad_workflow
parameters: None
status: failed
start_timestamp: Thu, 04 Oct 2018 12:38:45 UTC
end_timestamp: Thu, 04 Oct 2018 12:38:46 UTC
result:
  errors:
  - message: malformed string
    task_id: task1
  output: null

Do the same thing with good_workflow which sends in:

    input:
      value: [hello]

and the result:

root@f34287ba9aa8:/# st2 run badtype.good_workflow
..
id: 5bb60adc668fd406fff4d78a
action.ref: badtype.good_workflow
parameters: None
status: succeeded
start_timestamp: Thu, 04 Oct 2018 12:43:08 UTC
end_timestamp: Thu, 04 Oct 2018 12:43:11 UTC
result:
  output: null
+--------------------------+------------------------+-------+--------------------+-------------------------------+
| id                       | status                 | task  | action             | start_timestamp               |
+--------------------------+------------------------+-------+--------------------+-------------------------------+
| 5bb60add668fd407a23a2d0e | succeeded (1s elapsed) | task1 | badtype.take_array | Thu, 04 Oct 2018 12:43:09 UTC |
+--------------------------+------------------------+-------+--------------------+-------------------------------+

The workflow log shows:

2018-10-04 12:41:15,293 140443043906416 INFO workflows [-] [5bb60a6a668fd406fff4d784] Requesting execution for task "task1".
2018-10-04 12:41:15,293 140443043906416 INFO workflows [-] [5bb60a6a668fd406fff4d784] Processing task execution request for "task1".
2018-10-04 12:41:15,301 140443043906416 INFO workflows [-] [5bb60a6a668fd406fff4d784] Task execution "5bb60a6b668fd407a23a2d0a" created for task "task1".
2018-10-04 12:41:15,316 140443043906416 DEBUG config_loader [-] Attempting to get config
2018-10-04 12:41:15,317 140443043906416 DEBUG config_loader [-] Config: {}
2018-10-04 12:41:15,318 140443043906416 ERROR workflows [-] [5bb60a6a668fd406fff4d784] Failed task execution for task "task1".
Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/services/workflows.py", line 434, in request_task_execution
    ac_ex_ctx
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/param.py", line 298, in render_live_params
    live_params = _cast_params_from(params, context, [action_parameters, runner_parameters])
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/param.py", line 232, in _cast_params_from
    result[name] = _cast(context[name], param_schema)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/param.py", line 75, in _cast
    return cast(v)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/casts.py", line 39, in _cast_object
    return ast.literal_eval(x)
  File "/usr/lib/python2.7/ast.py", line 80, in literal_eval
    return _convert(node_or_string)
  File "/usr/lib/python2.7/ast.py", line 79, in _convert
    raise ValueError('malformed string')
ValueError: malformed string
2018-10-04 12:41:15,336 140443043906416 DEBUG workflows [-] [5bb60a6a668fd406fff4d784] Updating task execution from state "requested" to "failed".
2018-10-04 12:41:15,354 140443043906416 ERROR workflows [-] [5bb60a6a668fd406fff4d784] Failed task execution for "task1".
Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2actions/workflows/workflows.py", line 145, in handle_workflow_execution
    wf_svc.request_task_execution(wf_ex_db, task_id, task_spec, task_ctx, st2_ctx)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/services/workflows.py", line 460, in request_task_execution
    raise e
ValueError: malformed string
2018-10-04 12:41:15,373 140443043906416 DEBUG extension [-] found extension EntryPoint.parse('native = orquesta.composers.native:WorkflowComposer')
2018-10-04 12:41:15,374 140443043906416 DEBUG extension [-] found extension EntryPoint.parse('mock = orquesta.composers.mock:WorkflowComposer')
2018-10-04 12:41:15,374 140443043906416 DEBUG extension [-] found extension EntryPoint.parse('mistral = orquesta.composers.mistral:WorkflowComposer')
2018-10-04 12:41:15,375 140443043906416 INFO workflows [-] [5bb60a6a668fd406fff4d784] Updating workflow execution from state "running" to "failed".
2018-10-04 12:41:15,418 140443043906416 ERROR workflows [-] [5bb60a6a668fd406fff4d784] Workflow execution completed with errors. (task_id=u'task1',message=u'malformed string')
EXPECTED RESULTS

I expected to either have it "just work" like the direct action run works, or to have it error out with a message indicating the parameter name that was bad, and why it was bad. In this case saying, "not an array" perhaps instead of "malformed string". I guess the command line argument processing is smart enough to convert all instances of value into array members, but this doesn't happen from a workflow.

ACTUAL RESULTS

See steps to reproduce.

m4dcoder commented 6 years ago

I agree that we can do better with the error message and identifying which input parameters the type error refers to. However, we won't be handling variable data type like the CLI. From the CLI, user can only pass in string and the CLI makes assumption and some extra effort to take care of that for the user. However in workflow, the developer has more tools and control to work with the data, its type, and transformation.

jeking3 commented 6 years ago

A better error message is a sufficient resolution.

stale[bot] commented 5 years ago

Thanks for contributing to this issue. As it has been 90 days since the last activity, we are automatically marking is as stale. If this issue is not relevant or applicable anymore (problem has been fixed in a new version or similar), please close the issue or let us know so we can close it. On the contrary, if the issue is still relevant, there is nothing you need to do, but if you have any additional details or context which would help us when working on this issue, please include it as a comment to this issue.