Skip to content

add support for jinja do statements, add unit test#1314

Merged
blackboxsw merged 2 commits into
canonical:mainfrom
thetoolsmith:jinja-add-do-extension
Mar 3, 2022
Merged

add support for jinja do statements, add unit test#1314
blackboxsw merged 2 commits into
canonical:mainfrom
thetoolsmith:jinja-add-do-extension

Conversation

@thetoolsmith
Copy link
Copy Markdown
Contributor

Proposed Commit Message

Adding support for jinja do statements in template rendering.

summary: adding support for jinja 'do' statements in jinja templating

Support for jinja do statements will prevent having to workaround the following exception:
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'do'.

LP: #1962759

Additional Context

Test Steps

When processing the following example, the jinja exception is thrown.

{% set data_result = [] %}
{% set data_input = [1,2,3] %}
{% for i in data_input %}
{% do data_result.append(i) %}
{% endfor %}
{{data_result}}

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the bug and quick PR @thetoolsmith. I'll await confirmation on the CLA signing
which should become available to me tomorrow.

Confirmed "do" extension is present and functions properly without error on Ubuntu Bionic 18.04 (python3-jinja2 v. 2.10) and later.

Simple test with this changset generates the updated list output without printing the None return value from the append function call"

$ cloud-init query --format "{% set r = [] %}{% set input = [1,2,3] %}{% for i in input %}{% do r.append(i) %}{% endfor %}{{r}}"
[1, 2, 3]

Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm @thetoolsmith has signed the Contributor License Agreement for cloud-init, welcome to the project and thanks for your submission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants