StackStorm / StackStorm/st2

st2 rule ValidationError after upgrade from st2 2.6.0 to 2.7.2 (Jinja not rendering properly?)

Open
#4,156 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug status:to be verified
Dominant language
Python
Stars
6.5k
Forks
787
PR merge metrics
No merged PRs in 30d

Description

ISSUE TYPE
  • Bug Report
STACKSTORM VERSION
st2 2.7.2, on Python 2.7

OS / ENVIRONMENT / INSTALL METHOD

RPM installation on CentOS 7.x

SUMMARY

I have an st2 rule definition that was previously working fine under st2 2.6.0. After upgrading to st2 2.7.2 (with no changes to the rule definition), I am now finding it is throwing a ValidationError against one of the action parameters in the rule definition:

Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/rules/enforcer.py", line 94, in enforce
    execution_db = self._do_enforce()
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/rules/enforcer.py", line 143, in _do_enforce
    additional_contexts=additional_contexts)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2reactor/rules/enforcer.py", line 199, in _invoke_action
    liveaction_db, execution_db = action_service.create_request(liveaction_db)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/services/action.py", line 89, in create_request
    allow_default_none=True)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/schema/__init__.py", line 294, in validate
    jsonschema.validate(instance=instance, schema=schema, cls=cls, *args, **kwargs)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/jsonschema/validators.py", line 541, in validate
    cls(schema, *args, **kwargs).validate(instance)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/jsonschema/validators.py", line 130,
   in validate
    raise error
ValidationError: u'{{trigger.body.pullrequest_id}}' is not of type u'integer'
Failed validating u'type' in schema['properties'][u'prid']:
    {u'description': u'Pull request ID',
     u'required': True,
     u'type': u'integer'}

however the actual trigger body payload for the rule from st2rulesengine.log seems to be the correct (integer) type:

'payload': {'body': {u'request_user': u'ReRunner', u'pullrequest_id': 2401, ...

Seems like st2 is not rendering the Jinja before validating it.

As suggested in Slack, I also tried casting the parameter with | int in the rule definition but that doesn't appear to address the problem, still seems like the Jinja isn't rendered.

Here's my rule declaration:

---
    name: "reset_pr_bldstat"
    pack: "pxops"
    description: "Reset pull request build status"
    enabled: true
    trigger:
        type: "core.st2.webhook"
        description: "Reset PR build status incoming webhook"
        parameters:
          url: "pr/build/status/reset"
    criteria:
        trigger.body.webhook_event:
          type: "equals"
          pattern: "prbuild_reset_status"
    action:
         ref: "pxops.reset_build_status"
         parameters:
            repo: "{{trigger.body.repository}}"
            prid: "{{trigger.body.pullrequest_id}}"
            requestUser: "{{trigger.body.request_user}}"

This seems similar to this issue: https://github.com/StackStorm/st2/issues/4050

Some discussion of this on the Slack forum:

https://stackstorm-community.slack.com/archives/C066APT88/p1527787880000773

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

Reproduce the rule using the supplied StackStorm 2.7.2 configuration and webhook payload. Start in st2reactor/rules/enforcer.py and st2common/services/action.py, then follow the schema validation in st2common/util/schema/init.py. Compare the Jinja parameter handling with 2.6.0 and verify that the integer parameter validates before action creation.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.