Skip to content

Commit

Permalink
Avoid TypeError NoneType with lookups (#2852)
Browse files Browse the repository at this point in the history
Fixes: #2846
  • Loading branch information
ssbarnea authored Dec 31, 2022
1 parent 1d6f642 commit be5ed6c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 741
PYTEST_REQPASS: 742

steps:
- name: Activate WSL1
Expand Down
10 changes: 10 additions & 0 deletions examples/playbooks/find_children.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# Bug reproducer https://github.com/ansible/ansible-lint/issues/2846
- name: Play
hosts: localhost
gather_facts: false
connection: local
roles:
- role: acme.sample4
vars:
date_ko_1: "{{ lookup('pipe', 'date') }}"
3 changes: 3 additions & 0 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ def _roles_children(
) -> list[Lintable]:
# pylint: disable=unused-argument # parent_type)
results: list[Lintable] = []
if not v:
# typing does not prevent junk from being passed in
return results
for role in v:
if isinstance(role, dict):
if "role" in role or "name" in role:
Expand Down
5 changes: 5 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,8 @@ def test_nested_items() -> None:
match=r"Call to deprecated function ansiblelint\.utils\.nested_items.*"
):
assert list(utils.nested_items(data)) == items


def test_find_children() -> None:
"""Verify correct function of find_children()."""
utils.find_children(Lintable("examples/playbooks/find_children.yml"))

0 comments on commit be5ed6c

Please sign in to comment.