StackStorm / StackStorm/st2

Rendering rule action parameters with quoted strings causes an error

Open
#4,696 5 comments 1 reaction 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 invoking a rule that processes a trigger with a value containing a quoted string causes an error.

ISSUE TYPE
  • Bug Report
STACKSTORM VERSION
# st2 --version
st2 3.0.0, on Python 2.7.5
OS / ENVIRONMENT / INSTALL METHOD
CentOS 7.6
Puppet-st2
STEPS TO REPRODUCE

rule.yaml

---
name: "quoted_param_in_trigger_bug"
pack: "default"
description: "Demos how quoted values in a trigger instance cause render failures in a rule."
enabled: true

trigger:
  type: "core.st2.key_value_pair.update"

criteria: {}
action:
  ref: "examples.test"
  parameters:
    data:
      test: "{{ trigger.object.value }}"

trigger.yaml (yes, this file needs to be called .yaml even though it has JSON data in it)

{
    "id": "5ceed2bb9387ef0cefd1384b", 
    "occurrence_time": "2019-05-29T14:43:07.000000Z", 
    "payload": {
        "object": {
            "encrypted": false, 
            "id": "5ceed29d9387ef2a25148f26", 
            "name": "nick_test", 
            "scope": "st2kv.system", 
            "secret": false, 
            "uid": "key_value_pair:st2kv.system:nick_test", 
            "value": "Nick Test \"quoted string data\" blah"
        }
    }, 
    "status": "processed", 
    "trigger": "core.st2.key_value_pair.update"
}
EXPECTED RESULTS
$ st2-rule-tester --rule=./rule.yaml --trigger-instance=./trigger.yaml --config-file=/etc/st2/st2.conf
2019-05-29 14:49:24,439 INFO [-] Connecting to database "st2" @ "127.0.0.1:27017" as user "stackstorm".
2019-05-29 14:49:24,443 INFO [-] Successfully connected to database "st2" @ "127.0.0.1:27017" as user "stackstorm".
2019-05-29 14:49:24,592 INFO [-] Validating rule default.quoted_param_in_trigger_bug for st2.key_value_pair.update.
2019-05-29 14:49:24,592 INFO [-] 1 rule(s) found to enforce for st2.key_value_pair.update.
2019-05-29 14:49:24,593 INFO [-] Failed to retrieve config for pack <Mock name='mock.pack' id='139681899526160'> and user stanley: 'Mock' object is not iterable
2019-05-29 14:49:24,598 INFO [-] Action parameters resolved to:
2019-05-29 14:49:24,598 INFO [-]        data: {u'test': u'Nick Test "quoted string data" blah'}
2019-05-29 14:49:24,598 INFO [-] === RULE MATCHES ===
ACTUAL RESULTS

Note: i have removed a bunch of the exception catching code so we can see the real stack trace
instead of the "masked" version that hides the root of the issue.

$ st2-rule-tester --rule=./rule.yaml --trigger-instance=./trigger.yaml --config-file=/etc/st2/st2.conf
2019-05-29 14:48:54,608 INFO [-] Connecting to database "st2" @ "127.0.0.1:27017" as user "stackstorm".
2019-05-29 14:48:54,612 INFO [-] Successfully connected to database "st2" @ "127.0.0.1:27017" as user "stackstorm".
2019-05-29 14:48:54,752 INFO [-] Validating rule default.quoted_param_in_trigger_bug for st2.key_value_pair.update.
2019-05-29 14:48:54,752 INFO [-] 1 rule(s) found to enforce for st2.key_value_pair.update.
2019-05-29 14:48:54,753 INFO [-] Failed to retrieve config for pack <Mock name='mock.pack' id='140023090276368'> and user stanley: 'Mock' object is not iterable
Traceback (most recent call last):
  File "/usr/bin/st2-rule-tester", line 21, in <module>
    rule_tester.main()
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/cmd/rule_tester.py", line 58, in main
    matches = tester.evaluate()
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/rules/tester.py", line 106, in evaluate
    additional_contexts=additional_contexts)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/rules/enforcer.py", line 84, in get_resolved_parameters
    additional_contexts=additional_contexts)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/param.py", line 312, in render_live_params
    context = _resolve_dependencies(G)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/param.py", line 224, in _resolve_dependencies
    context[name] = _render(node, context)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/param.py", line 208, in _render
    result = json.loads(result)
  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting ',' delimiter: line 1 column 22 (char 21)

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 st2common/util/param.py, especially _render and _resolve_dependencies, then reproduce the issue with st2-rule-tester using the provided rule.yaml and trigger.yaml. Trace why the quoted trigger value produces invalid JSON during rendering. Done means the command completes without the ValueError and resolves data.test to the full quoted string shown in the expected results.

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.