-
-
Notifications
You must be signed in to change notification settings - Fork 750
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
Jinja is not rendered in action default values prior to schema checking #3820
Comments
@nmaludy: The problem doesn't seem to be jinja filters. It is the quotes around the integer. The default value for integer type should be a number instead of string (this is expected behavior). $ st2 run examples.mistral-basic cmd="ls"
ERROR: 400 Client Error: Bad Request
MESSAGE: '2020' is not of type 'integer' for url: http://127.0.0.1:9101/v1/executions Action metadata---
description: Run a local linux command
enabled: true
runner_type: mistral-v2
entry_point: workflows/mistral-basic.yaml
name: mistral-basic
pack: examples
parameters:
cmd:
required: true
type: string
timeout:
type: integer
default: 60
kv_test:
type: integer
default: "2020" and you are interested in providing default value for params. in action meta from datastore. For that you can do something like this: Action metadata (does't need jinja filter)---
description: Run a local linux command
enabled: true
runner_type: mistral-v2
entry_point: workflows/mistral-basic.yaml
name: mistral-basic
pack: examples
parameters:
cmd:
required: true
type: string
timeout:
type: integer
default: 60
kv_test:
type: string #----> Use string and datastore will automatically take care of datatype for you.
default: "{{ st2kv.system.nick_test}}" Workflowversion: '2.0'
examples.mistral-basic:
description: A basic workflow that runs an arbitrary linux command.
type: direct
input:
- cmd
- timeout
- kv_test
output:
stdout: <% $.stdout %>
tasks:
task1:
action: core.local cmd="if echo <% $.kv_test %> | egrep -q '^[0-9]+$'; then echo 'yes'; else echo 'no';fi" #cmd=<% $.cmd %> timeout=<% $.timeout %>
publish:
stdout: <% task(task1).result.stdout %>
stderr: <% task(task1).result.stderr %> String in datastore$ st2 key set nick_test "123isnotnumber"
+------------------+----------------+
| Property | Value |
+------------------+----------------+
| name | nick_test |
| value | 123isnotnumber |
| expire_timestamp | |
+------------------+----------------+
$ st2 run examples.mistral-basic cmd=""
....
id: 5a0124a3de59a42542829c21
action.ref: examples.mistral-basic
parameters:
cmd: ''
status: succeeded
result_task: task1
result:
failed: false
return_code: 0
stderr: ''
stdout: 'no' #------> not a number
succeeded: true
start_timestamp: 2017-11-07T03:12:35.552628Z
end_timestamp: 2017-11-07T03:12:42.013246Z
+--------------------------+------------------------+-------+------------+-------------------------------+
| id | status | task | action | start_timestamp |
+--------------------------+------------------------+-------+------------+-------------------------------+
| 5a0124a3de59a42542829c24 | succeeded (1s elapsed) | task1 | core.local | Tue, 07 Nov 2017 03:12:35 UTC |
+--------------------------+------------------------+-------+------------+-------------------------------+ Integer in datastore$ st2 key set nick_test "123"
+------------------+-----------+
| Property | Value |
+------------------+-----------+
| name | nick_test |
| value | 123 |
| expire_timestamp | |
+------------------+-----------+
$ st2 run examples.mistral-basic cmd=""
...
id: 5a0124bbde59a42542829c26
action.ref: examples.mistral-basic
parameters:
cmd: ''
status: succeeded
result_task: task1
result:
failed: false
return_code: 0
stderr: ''
stdout: 'yes' #----> number
succeeded: true
start_timestamp: 2017-11-07T03:12:59.067428Z
end_timestamp: 2017-11-07T03:13:05.018635Z
+--------------------------+------------------------+-------+------------+-------------------------------+
| id | status | task | action | start_timestamp |
+--------------------------+------------------------+-------+------------+-------------------------------+
| 5a0124bbde59a42542829c29 | succeeded (0s elapsed) | task1 | core.local | Tue, 07 Nov 2017 03:12:59 UTC |
+--------------------------+------------------------+-------+------------+-------------------------------+
Hope this helps! |
@humblearner The example i gave was simplified to demonstrate the problem. This also breaks when doing something like: Objects---
description: Run a local linux command
enabled: true
runner_type: mistral-v2
entry_point: workflows/mistral-basic.yaml
name: mistral-basic
pack: examples
parameters:
cmd:
required: true
type: string
timeout:
type: integer
default: 60
kv_test:
type: object
default: "{{ st2kv.system.nick_test | from_json_string }}" st2 key set nick_test '{"test_key": "test_value}' In this case, in the workflow i want to utilize data within the object natively using Arrays---
description: Run a local linux command
enabled: true
runner_type: mistral-v2
entry_point: workflows/mistral-basic.yaml
name: mistral-basic
pack: examples
parameters:
cmd:
required: true
type: string
timeout:
type: integer
default: 60
kv_test:
type: array
default: "{{ st2kv.system.nick_test | from_json_string }}" st2 key set nick_test '["a", "b", "c"]' In this case, in the workflow i want to utilize data within the arra natively using |
This is happening because of two reasons. First, the actual execution request takes place before any rendering takes place. Second, even if this wasn't true, the ActionExecutions API controller is calling out to param_utils.render_live_params which only renders "live" params (meaning params being explicitly passed in, which doesn't include default values. So, when the controller requests an execution, the schema is checked, and this value is still an unrendered template, which is of course a string. So with this behavior, the value you're intending to get better also be a string. This behavior is more coincidental than intentional, so we should fix this. Note in the docs, each example of this is a string value - this is a bit misleading because the actual call to render final params doesn't happen until actual execution of the action. I'm looking at alternative approaches now, but figured I'd update the discussion with a root cause. I also see the reference to #3828 but as @Kami suggests, that's a much bigger change, so I'm looking to see if there's a less dangerous, temporary solution to this problem. Bottom line, we at least need to update docs to say only string values are supported for this, but ideally we can render these values before sending the request. |
Problem
When trying to call an action with Jinja for its default value an error is raised complaining about a type mismatch.
Action metadata
Error - CLI
Error - Logs
The text was updated successfully, but these errors were encountered: