New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the "traverse" jinja filter #48670

Merged
merged 2 commits into from Jul 20, 2018

Conversation

Projects
None yet
3 participants
@bbinet
Contributor

bbinet commented Jul 19, 2018

This filter can be really useful in states to select some leaf pillar data or fallback with a default value.

The code is trivial as it is just a matter of exposing the existing traverse_dict_and_list function as a jinja filter through the @jinja_filter('traverse') decorator.
That is the reason why it seems safe to merge it in the 2018.3 branch instead of the develop branch.

Add the "traverse" jinja filter
which can be really useful in states to select some leaf pillar data or
fallback with a default value.
@mirceaulinic

Nice one. I ended up with a custom execution module, e.g,, {{ salt.my_utils.traverse(my_dict) }}, but this filter would be better IMO.

.. jinja_ref:: traverse
``traverse``
--------------

This comment has been minimized.

@mirceaulinic

mirceaulinic Jul 20, 2018

Member

The doc checks might trigger a warning here (the line of - must be as long as the title above).

This comment has been minimized.

@bbinet

bbinet Jul 20, 2018

Contributor

Ok

``traverse``
--------------
.. versionadded:: 2018.3.3

This comment has been minimized.

@mirceaulinic

mirceaulinic Jul 20, 2018

Member

.. versionadded:: Fluorine

This comment has been minimized.

@bbinet

bbinet Jul 20, 2018

Contributor

Ok

This comment has been minimized.

@bbinet

bbinet Jul 20, 2018

Contributor

In fact, would it be possible to include this patch in the next minor version of salt?

As I told in the PR description, the code is trivial as it is just a matter of exposing the existing traverse_dict_and_list function as a jinja filter through the @jinja_filter('traverse') decorator.
So it seems safe to me to merge it in the 2018.3 branch instead of the develop branch.

Returns:
.. code-block:: python

This comment has been minimized.

@mirceaulinic

mirceaulinic Jul 20, 2018

Member

.. code-block:: text, I think (again, RST might complain about it).

This comment has been minimized.

.. code-block:: python
{'c1': 'foo'}

This comment has been minimized.

@rallytime

rallytime Jul 20, 2018

Contributor

These code-block sections need to be a full indent for this to display properly in the docs. Can you fix this one, as well as the rest of the code-block sections?

This comment has been minimized.

@bbinet

bbinet Jul 20, 2018

Contributor

@rallytime these python code-block sections already exists in this index.rst file and renders correctly in the docs. See for example the compare_lists filter doc: https://docs.saltstack.com/en/latest/topics/jinja/index.html#compare-lists

This comment has been minimized.

@rallytime

rallytime Jul 20, 2018

Contributor

Interesting. Usually sphinx generates a warning about that I thought. shrug

@rallytime rallytime merged commit 5a6f7a0 into saltstack:2018.3 Jul 20, 2018

7 of 8 checks passed

jenkins/pr/py2-centos-7 running py2-centos-7...
Details
WIP ready for review
Details
continuous-integration/jenkins/pr-merge This commit looks good
Details
jenkins/pr/docs The docs job has passed
Details
jenkins/pr/lint The lint job has passed
Details
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has passed
Details
jenkins/pr/py3-centos-7 The py3-centos-7 job has passed
Details
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has passed
Details

@bbinet bbinet deleted the bbinet:traverse branch Jul 20, 2018

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