StackStorm / StackStorm/st2

st2.kv.set_object does not take list

Open
#4,943 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

SUMMARY

When trying to set a list of dict in st2kv, st2 complains about my list is not of type object.

STACKSTORM VERSION

st2 3.1.0, on Python 2.7.6

OS, environment, install method

docker ubuntu image with st2 docker-compose

Steps to reproduce the problem

trying to append a dict to a list of dict in orquesta:

  set_st2kv:
    action: st2.kv.set_object
    input:
      key: "home_dir_to_check"
      value: "{{ ctx('check_list') + [{ 'user': ctx('user'), 'execution_id': ctx('execution_id'), 'send_to': ctx('recipient') }] }}"

Expected Results

Be able to set a list to variable. As st2 key set allows you to put list into variable

Actual Results

{
  "output": null,
  "errors": [
    {
      "message": "ValidationError: [{u'user': u'moet', u'execution_id': u'04129840921834'}, {u'user': u'dsizer', u'execution_id': u'498843502233'}, {u'user': u'moet', u'execution_id': u'1290i029810984', u'send_to': u'moet'}] is not of type u'object'\n\nFailed validating u'type' in schema['properties'][u'value']:\n    {u'required': True, u'type': u'object'}\n\nOn instance[u'value']:\n    [{u'execution_id': u'04129840921834', u'user': u'moet'},\n     {u'execution_id': u'498843502233', u'user': u'dsizer'},\n     {u'execution_id': u'1290i029810984',\n      u'send_to': u'moet',\n      u'user': u'moet'}]",
      "type": "error",
      "route": 0,
      "task_id": "set_st2kv"
    }
  ]
}

I think it is mainly in the kv_set_object.py, which says:

---
name: 'kv.set_object'
enabled: true
description: 'Serialize and store object in a datastore'
runner_type: python-script
entry_point: kv_set_object.py
parameters:
  key:
    required: True
    type: string
  value:
    required: True
    type: object  # <== seems it really want object and nothing else
  ttl:
    type: integer
    description: 'Optional TTL for the provided value'
    required: False

But I think list should also be allowed in this scenario

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 kv_set_object.py and the action definition shown in the issue to trace how the value input is validated and stored. Check the existing tests for kv.set_object, then verify that a list of dictionaries is accepted while existing object behavior remains valid.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.