Skip to content

Commit be5ed6c

Browse files
authored
Avoid TypeError NoneType with lookups (#2852)
Fixes: #2846
1 parent 1d6f642 commit be5ed6c

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY
7070
# Number of expected test passes, safety measure for accidental skip of
7171
# tests. Update value if you add/remove tests.
72-
PYTEST_REQPASS: 741
72+
PYTEST_REQPASS: 742
7373

7474
steps:
7575
- name: Activate WSL1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
# Bug reproducer https://github.com/ansible/ansible-lint/issues/2846
3+
- name: Play
4+
hosts: localhost
5+
gather_facts: false
6+
connection: local
7+
roles:
8+
- role: acme.sample4
9+
vars:
10+
date_ko_1: "{{ lookup('pipe', 'date') }}"

src/ansiblelint/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ def _roles_children(
448448
) -> list[Lintable]:
449449
# pylint: disable=unused-argument # parent_type)
450450
results: list[Lintable] = []
451+
if not v:
452+
# typing does not prevent junk from being passed in
453+
return results
451454
for role in v:
452455
if isinstance(role, dict):
453456
if "role" in role or "name" in role:

test/test_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,8 @@ def test_nested_items() -> None:
387387
match=r"Call to deprecated function ansiblelint\.utils\.nested_items.*"
388388
):
389389
assert list(utils.nested_items(data)) == items
390+
391+
392+
def test_find_children() -> None:
393+
"""Verify correct function of find_children()."""
394+
utils.find_children(Lintable("examples/playbooks/find_children.yml"))

0 commit comments

Comments
 (0)