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.07k stars 749 forks source link

Orquesta Runtime Context : Map value is not updating after publish. #5285

Closed buddhika-ranasinghe closed 3 years ago

buddhika-ranasinghe commented 3 years ago

SUMMARY

I am trying to update a variable in a map which is populated by publishing the result of a core.http action. It remains still the same even though I updated the title value by publishing the value to map again. Please see the workflow I have created to simulate the same problem.

STACKSTORM VERSION

st2 3.3.0, on Python 3.6.9

OS, environment, install method

Post what OS you are running this on, along with any other relevant information/

Docker | Host OS : Windows 10

Steps to reproduce the problem

Please see my workflow.

version: 1.0

description: A basic sequential workflow to handle ToDos.

input:
  - url : "https://jsonplaceholder.typicode.com/todos/1"

vars:
  - todo_details : {}
  - failure_message: ""
  - final_result: "Initial Stage"
  - current_stage: "Initial Stage" 

output:
  - final_result: <% ctx().final_result %>
  - failure_message: <% ctx().failure_message %>
  - current_stage: "<% ctx().current_stage %>"

tasks:
  get_todo_details:
    action: core.http url="<% ctx().url %>"
    retry:
      delay: 10
      count: 3
    next:
      - when: <% succeeded() %>
        publish:
          - todo_details: <% result().body %>
          - current_stage: "get_todo_details:succeeded"
        do: change_title    
      - when: <% failed() %>
        publish:
          - failure_message: "Failed while trying to get todo"
          - final_result: <% result() %>
          - current_stage: "get_todo_details:failed"
        do: noop   

  change_title:
    action: core.noop
    next :
      - when: <% succeeded() %>
        publish:
          - todo_details.title : "Hello World Title - Changed Once"
          - current_stage: "change_title:succeeded"
        do: publish_results 

  publish_results:
    action: core.noop
    next :
      - when: <% succeeded() %>
        publish:
          - final_result : "<% ctx().todo_details %>"
          - current_stage: "publish_results:succeeded"
        do: noop

Expected Results

{
  "output": {
    "final_result": {
      "userId": 1,
      "id": 1,
      "title": "Hello World Title - Changed Once",
      "completed": false
    },
    "failure_message": "",
    "current_stage": "publish_results:succeeded"
  }
}

Actual Results

{
  "output": {
    "final_result": {
      "userId": 1,
      "id": 1,
      "title": "delectus aut autem",
      "completed": false
    },
    "failure_message": "",
    "current_stage": "publish_results:succeeded"
  }
}

Thanks!

blag commented 3 years ago

You cannot publish to JSONPaths like you are attempting to do. In other words, as far as I am aware, this mechanism is not supported:

tasks:
  ...
  task_name:
    action: ...
    next :
      - when: ...
        publish:
          - todo_details.title : "Hello World Title - Changed Once"
          #             ^^^^^^ - won't work
        do: ...

What that will do is publish to a variable named todo_details.title, it will not update the dictionary.

To update a single dictionary key, you will need to use YAQL to set the key, and then publish the entire dictionary back to the dictionary variable name that you want to update. Something like this:

tasks:
  ...
  task_name:
    action: ...
    next :
      - when: ...
        publish:
          - todo_details : <% ctx().todo_details.set("title", "Hello World Title - Changed Once") %>
        do: ...
blag commented 3 years ago

Since you're not the first person to have this question, I have updated the Orquesta Implementation Patterns page in this project's wiki. Hopefully that makes the solution slightly more discoverable for users.

I'm going to close this issue, but if it doesn't work, or if you still need help, feel free to drop a comment and I'll be happy to reopen it.