StackStorm / StackStorm/st2

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

Open
#4,375 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
Python
Stars
6.5k
Forks
787
PR merge metrics
No merged PRs in 30d

Description

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
  • Bug Report
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with st2common/util/param.py and st2common/util/casts.py, following the traceback through parameter rendering and array casting. Reproduce the failure with the badtype pack and compare it with bad_workflow and good_workflow. Done means the invalid workflow input produces a useful error that identifies the parameter and why its value is invalid.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.