StackStorm / StackStorm/st2

Feature: Use Jinja's new NativeEnvironment to get native types instead of strings!

Open
#3,828 7 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

It's really hard to deal with magically converting from Jinja strings back into native python types. Let's just skip the conversion and use native python types.

How you ask? Jinja has merged a pretty cool PR: pallets/jinja#708
Here's a quote from the new doc:

The default jinja2.Environment renders templates to strings. With NativeEnvironment, rendering a template produces a native Python type.

This consists of three basic parts: NativeCodeGenerator, NativeTemplate, and NativeEnvironment. Check out the code. This will land in Jinja 2.10.

This comes from an ansible PR by @jctanner: ansible/ansible#23943

I suspect that using NativeEnvironment would resolve (or make a big dent in) these:

  • #1231 Preserve type in ActionChain published vars
  • #2976 Complex types (other than string) in dynamic config
  • #3515 allow explicit casting of Jinja types
  • StackStorm-Exchange/stackstorm-ansible#14 Parsing directives !JSON, !AST, and !INT that convert strings (like from Jinja) to python types.
  • Plus, maybe it would be one component in allowing complex (ie non-string) data types in the datastore.

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 by reviewing Jinja's NativeEnvironment proposal and the existing string-to-native conversion paths implicated by issues #1231, #2976, and #3515. Determine which StackStorm rendering and datastore flows would need native types, then define tests covering those flows and verify that the listed conversion problems are addressed without breaking existing string rendering.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.