This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

How do I provide default array parameter for workflows from pack config when triggerred via rules/aliases

I have a mistral workflow that takes an input recipients of type array.
In my pack config, I have a config item default_recipients of type array. In the action metadata yaml file, for the parameter recipients I try to add a default value from the pack config as:

parameters:
  recipients:
    type: array
    default: "{{ config_context.default_recipients }}"

I have added the config default_recipients: ["[email protected]", "[email protected]"]

However, when I run this workflow, I get the error:

ValueError: Failed to cast value "{{ config_context.default_recipients }}" (type: unicode) for parameter "recipients" of type "array": malformed string. Perhaps the value is of an invalid type?

It appears that the validation is happening before the Jinja2 evaluation.
What am I missing here?
How do I make this work?

I am seeing the same problem even with parameters of type integer when trying to use a default using jijna expression.
This works for parameters of type string, but doesn’t work with other types - integer, array

Edit: This seems to be a problem with action-chains too.

Can you post your config schema for the pack here?

  default_recipients:
    description: "List of email addresses"
    type: "array"
    required: true

I’m unable to reproduce this on st2 v2.6. Here’s what I used for my test.

  • pack config schema
k1:
  type: array
  default:
    - foo
    - bar
  • config file after running st2 pack config
k1:
- foo
- bar
  • mistral workflow for testing
name: test_cfg_ctx
pack: sandbox
runner_type: mistral-v2
description: For testing
enabled: true
entry_point: workflows/test_cfg_ctx.yaml
parameters:
  k1:
    type: array
    required: true
    default: "{{ config_context.k1 }}"
version: '2.0'

sandbox.test_cfg_ctx:
    input:
      - k1
    tasks:
        t1:
            action: core.local
            input:
                cmd: echo "<% $.k1[0] + $.k1[1] %>"
  • output of workflow execution
id: 5ab405701e2e241599498c15
action.ref: sandbox.test_cfg_ctx
parameters: 
  k1:
  - foo
  - bar
status: succeeded
result_task: t1
result: 
  failed: false
  return_code: 0
  stderr: ''
  stdout: foobar
  succeeded: true
start_timestamp: Thu, 22 Mar 2018 19:35:12 UTC
end_timestamp: Thu, 22 Mar 2018 19:35:13 UTC
+--------------------------+------------------------+------+------------+-----------------+
| id                       | status                 | task | action     | start_timestamp |
+--------------------------+------------------------+------+------------+-----------------+
| 5ab405701e2e241599498c18 | succeeded (0s elapsed) | t1   | core.local | Thu, 22 Mar     |
|                          |                        |      |            | 2018 19:35:12   |
|                          |                        |      |            | UTC             |
+--------------------------+------------------------+------+------------+-----------------+

Thanks for your response!

This happened when I triggered the action using a rule or alias. Sorry, didn’t mention it earlier (probably thought it wasn’t relevant).
Can you check triggering the same action using some rule?

I’ve shown it’s working. Can you check your rule(s) first?

The same rule works when I remove this parameter from the action metadata/definition or hardcode those values.

My rule looks like this:

---
trigger:
  type: core.st2.generic.notifytrigger
  parameters: {}
criteria:
  trigger.channel:
    pattern: "custom_notify"
    type: "equals"
action:
  ref: "mypack.send_notification"
  parameters:
    message: "{{ trigger.message }}"
    data: "{{ trigger.data }}"

Have you tried manually executing the action with the parameter defined?

I tried it again.
Here are my actions:

Metadata for Action that takes the array as param

---
name: test_action
pack: test
runner_type: mistral-v2
description: Testing arrays
enabled: true
entry_point: workflows/test_action.yaml
parameters:
  recipients:
    required: true
    type: array
    description: list of email addresses
    default: "{{ config_context.default_recipients }}"

Action definition

version: '2.0'

test.test_action:
    input:
      - recipients
    tasks:
        t1:
            action: core.local
            input:
                cmd: echo "{{ _.recipients|join(', ') }}"

The rule in question

---
name: test_rule
pack: test
description: Rule to send notifications on completion of task.
enabled: true

trigger:
  type: core.st2.generic.notifytrigger
  parameters: {}
criteria:
  trigger.channel:
    pattern: "dummy"
    type: "equals"
action:
  ref: "test.test_action"

Action that generates the notification (just for reference)

---
description: Action that executes an arbitrary Linux command on the localhost.
enabled: true
entry_point: ''
name: test_notify_action
notify:
  on-complete:
    routes:
    - dummy
    message: '42'
parameters:
  cmd:
    description: Arbitrary Linux command to be executed on the remote host(s).
    required: true
    type: string
  sudo:
    immutable: true
runner_type: "local-shell-cmd"

I run the action test_notify_action to generate the notification that would trigger the action in question:

# st2 run test.test_notify_action cmd="echo 'tango'"

.
id: 5ab40ecf25acbf5b0b4c747e
status: succeeded
parameters: 
  cmd: echo 'tango'
result: 
  failed: false
  return_code: 0
  stderr: ''
  stdout: tango
  succeeded: true

It succeeds but fail to trigger the action.
So I see the logs and find this:

2018-03-23 01:45:12,995 140439250711088 INFO matcher [-] 1 rule(s) found to enforce for st2.generic.notifytrigger.
2018-03-23 01:45:12,999 140439250711088 INFO engine [-] Matched 1 rule(s) for trigger_instance 5ab40ed025acbf03cc58e55f (trigger=core.st2.generic.notifytrigger)
2018-03-23 01:45:13,002 140439250711088 INFO enforcer [-] Invoking action test.test_action for trigger_instance 5ab40ed025acbf03cc58e55f with params {}.
2018-03-23 01:45:13,063 140439250711088 ERROR enforcer [-] Failed kicking off execution for rule RuleDB(action=ActionExecutionSpecDB@140439245111760(ref="test.test_action", parameters="{}"), criteria={u'trigger.channel': {u'pattern': u'dummy', u'type': u'equals'}}, description="Rule to send notifications on completion of task.", enabled=True, id=5ab40ca425acbf2fbd8f2c68, name="test_rule", pack="test", ref="test.test_rule", tags=[], trigger="core.st2.generic.notifytrigger", type=RuleTypeSpecDB@140439245111888(ref="standard", parameters="{}"), uid="rule:test:test_rule").
Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/rules/enforcer.py", line 74, in enforce
    execution_db = self._do_enforce()
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/rules/enforcer.py", line 114, in _do_enforce
    return RuleEnforcer._invoke_action(self.rule.action, params, context)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/rules/enforcer.py", line 161, in _invoke_action
    liveaction, execution = action_service.request(liveaction)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/services/action.py", line 156, in request
    liveaction, execution = create_request(liveaction)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/services/action.py", line 87, in create_request
    allow_default_none=True)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/schema/__init__.py", line 293, in validate
    jsonschema.validate(instance=instance, schema=schema, cls=cls, *args, **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/jsonschema/validators.py", line 541, in validate
    cls(schema, *args, **kwargs).validate(instance)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/jsonschema/validators.py", line 130, in validate
    raise error
ValidationError: u'{{ config_context.default_recipients }}' is not of type u'array'

Failed validating u'type' in schema['properties'][u'recipients']:
    {u'default': u'{{ config_context.default_recipients }}',
     u'description': u'list of email addresses',
     u'required': True,
     u'type': u'array'}

On instance[u'recipients']:

...

when I run the action directly, it works fine (like you observed).

# st2 run test.test_action
....
id: 5ab4104725acbf5b0b4c7484
action.ref: test.test_action
parameters: 
  recipients:
  - [email protected]
  - [email protected]
status: succeeded
result_task: t1
result: 
  failed: false
  return_code: 0
  stderr: ''
  stdout: [email protected], [email protected]
  succeeded: true
start_timestamp: Thu, 22 Mar 2018 20:21:27 UTC
end_timestamp: Thu, 22 Mar 2018 20:21:34 UTC
+--------------------------+------------------------+------+------------+-------------------------------+
| id                       | status                 | task | action     | start_timestamp               |
+--------------------------+------------------------+------+------------+-------------------------------+
| 5ab4104825acbf5b0b4c7487 | succeeded (1s elapsed) | t1   | core.local | Thu, 22 Mar 2018 20:21:28 UTC |
+--------------------------+------------------------+------+------------+-------------------------------+

config schema:

---
  default_recipients:
    description: "Comma separated email addresses of the recipients to send the reports/notification"
    type: "array"
    required: true

Configuration:

default_recipients: ["[email protected]", "[email protected]"]

If it helps, I remember this failing when triggered using aliases too.

Please open an issue at st2 repo with the last set of information here.

created Default parameter type validation fails for non-string types when workflows are triggerred using rules/aliases · Issue #4050 · StackStorm/st2 · GitHub