st2kv inside the rules criteria is not working
Open
Nobody has claimed this yet.
stale
status:to be verified
- Dominant language
- Python
- Stars
- 6.5k
- Forks
- 787
- PR merge metrics
- No merged PRs in 30d
Description
Hi ,
I am trying to retreive datastore value inside the criteria of the rules as like below.
Yaml:
name: ticket-to-stackstorm-rule
pack: avmarmusecase
enabled: true
trigger:
type: "default.workflowinitiate"
criteria:
trigger.category:
pattern: "{{st2kv.system.db}}"
type: "equals"
trigger.item:
pattern: "Policy_Update"
type: "equals"
Error Log:
Traceback (most recent call last):
File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/rules/filter.py", line 118, in _check_criterion
criteria_context=payload_lookup.context
File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/rules/filter.py", line 189, in _render_criteria_pattern
context=criteria_context
File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/templating.py", line 86, in render_template_with_system_context
rendered = render_template(value=value, context=context)
File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/util/templating.py", line 53, in render_template
rendered = template.render(context)
File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "<template>", line 1, in top-level template code
File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/jinja/filters/complex_type.py", line 24, in to_complex
result = json.dumps(value)
File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
Please help on this issue.
Thanks
Arul
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in st2reactor/rules/filter.py at _check_criterion and _render_criteria_pattern, then follow the call into st2common/util/templating.py and the complex_type filter shown in the traceback. Reproduce the supplied rule and datastore expression to determine why rendering fails. Done means the criteria can retrieve the datastore value without the JSON serialization error and the behavior is covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100