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

YAQL dict's keys() and items() methods are broken in orquesta workflows #5721

Open igcherkaev opened 2 years ago

igcherkaev commented 2 years ago

SUMMARY

Two YAQL's methods for dict type are broken: keys() and items().

STACKSTORM VERSION

Paste the output of st2 --version:

$ st2 --version
st2 3.6.0, on Python 3.6.8
OS, environment, install method

Standard installation on Centos 7. The issue confirmed on a test instance by Carlos. His test instance is running st2 3.7.0.

Steps to reproduce the problem

Meta:

---
pack: "playground"
name: "wf_orquesta_test9"
description: "Orquesta test 9"
runner_type: orquesta
enabled: true
entry_point: "workflows/wf_orquesta_test9.yaml"

Orquesta workflow:

---
version: '1.0'
vars:
  - var1:
      key1:
        - item1
        - item2

tasks:
  task1:
    with:
      items: i in <% ctx().var1.keys() %>
    action: core.noop

Expected Results

One iteration of task1 to be executed successfully. According to YAQL docs: https://yaql.readthedocs.io/en/latest/standard_library.html#keys and https://yaql.readthedocs.io/en/latest/standard_library.html#items - both methods should allow you to iterate over items. I believe this is some kind of regression bug, as this approach used to work on st2 3.4.1. Some time after that it got broken.

Actual Results

id: 63121fb20fd8433f83f4cf8b
action.ref: playground.wf_orquesta_test9
parameters: None
status: failed (1s elapsed)
start_timestamp: Fri, 02 Sep 2022 15:22:26 UTC
end_timestamp: Fri, 02 Sep 2022 15:22:27 UTC
log: 
  - status: requested
    timestamp: '2022-09-02T15:22:26.964000Z'
  - status: scheduled
    timestamp: '2022-09-02T15:22:27.121000Z'
  - status: running
    timestamp: '2022-09-02T15:22:27.175000Z'
  - status: failed
    timestamp: '2022-09-02T15:22:27.353000Z'
result: 
  errors:
  - message: 'TypeError: The value of "<% ctx().var1.keys() %>" is not type of list.'
    route: 0
    task_id: task1
    type: error
  output: null

P.S. For those who run into the same issue, there is a workaround:

  task1:
    with:
      items: i in {{ ctx().var1.keys() | list }}
igcherkaev commented 2 years ago

There's an existing issue that's been already reported: https://github.com/StackStorm/orquesta/issues/247 Let me know if you'd like to close this one or that one to avoid duplicates.

igcherkaev commented 2 years ago

Another report for the same issue: https://github.com/StackStorm/st2/issues/5547

igcherkaev commented 2 years ago

@cognifloyd suggested using this and it seems to be working, in case other YAQL expressions are broken:

tasks:
  task1:
    with:
      items: i in <% ctx().var1.keys().toList() %>
    action: core.noop