-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
lookup(first_found) with errors=ignore returns empty string #56775
Labels
affects_2.9
This issue/PR affects Ansible v2.9
bug
This issue/PR relates to a bug.
support:community
This issue/PR relates to code supported by the Ansible community.
Comments
Files identified in the description: If these files are inaccurate, please update the |
ianw
added a commit
to ianw/ansible
that referenced
this issue
May 28, 2019
The jinja2 query() function (or lookup with wantslist=True, which is the same thing) should always return a list. However, if you combine a query with errors='ignore' and take the error path, the current code returns a None value. This is important in a case such as - name: Conditional include file import_tasks: '{{ item }}' vars: params: files: - path/file1.yaml - path/file2.yaml loop: "{{ q('first_found', params, errors='ignore') }}" If neither file1.yaml or file2.yaml exist, this should do nothing by returning an empty list to the loop. Currently if you run the above task you'll get a rather unhelpful: Invalid data passed to 'loop', it requires a list, got this instead: . This change ensures that when a query ignores an error, it returns a empty list. The errors='ignore' case is tested in several variants with first_found. The extant (but deprecated) "skip: True" for first_found doesn't seem to be explicitly tested; a test is added here to avoid regressions before removal in 2.12. This fixes a regression you'll hit if you follow the suggestion in the deprecation message included with e17a2b5 to use errors=ignore over "skip: True" for first_found. This change adds an example that points out the query/lookup difference and also fixes the error message to not mention the now deprecated "skip: True". Closes ansible#56775
StephenSorriaux
pushed a commit
to StephenSorriaux/ansible
that referenced
this issue
May 29, 2019
The jinja2 query() function (or lookup with wantslist=True, which is the same thing) should always return a list. However, if you combine a query with errors='ignore' and take the error path, the current code returns a None value. This is important in a case such as - name: Conditional include file import_tasks: '{{ item }}' vars: params: files: - path/file1.yaml - path/file2.yaml loop: "{{ q('first_found', params, errors='ignore') }}" If neither file1.yaml or file2.yaml exist, this should do nothing by returning an empty list to the loop. Currently if you run the above task you'll get a rather unhelpful: Invalid data passed to 'loop', it requires a list, got this instead: . This change ensures that when a query ignores an error, it returns a empty list. The errors='ignore' case is tested in several variants with first_found. The extant (but deprecated) "skip: True" for first_found doesn't seem to be explicitly tested; a test is added here to avoid regressions before removal in 2.12. This fixes a regression you'll hit if you follow the suggestion in the deprecation message included with e17a2b5 to use errors=ignore over "skip: True" for first_found. This change adds an example that points out the query/lookup difference and also fixes the error message to not mention the now deprecated "skip: True". Closes ansible#56775
bcoca
pushed a commit
to bcoca/ansible
that referenced
this issue
Feb 21, 2020
The jinja2 query() function (or lookup with wantslist=True, which is the same thing) should always return a list. However, if you combine a query with errors='ignore' and take the error path, the current code returns a None value. This is important in a case such as - name: Conditional include file import_tasks: '{{ item }}' vars: params: files: - path/file1.yaml - path/file2.yaml loop: "{{ q('first_found', params, errors='ignore') }}" If neither file1.yaml or file2.yaml exist, this should do nothing by returning an empty list to the loop. Currently if you run the above task you'll get a rather unhelpful: Invalid data passed to 'loop', it requires a list, got this instead: . This change ensures that when a query ignores an error, it returns a empty list. The errors='ignore' case is tested in several variants with first_found. The extant (but deprecated) "skip: True" for first_found doesn't seem to be explicitly tested; a test is added here to avoid regressions before removal in 2.12. This fixes a regression you'll hit if you follow the suggestion in the deprecation message included with e17a2b5 to use errors=ignore over "skip: True" for first_found. This change adds an example that points out the query/lookup difference and also fixes the error message to not mention the now deprecated "skip: True". Closes ansible#56775
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
affects_2.9
This issue/PR affects Ansible v2.9
bug
This issue/PR relates to a bug.
support:community
This issue/PR relates to code supported by the Ansible community.
SUMMARY
lookup("first_found", whatever, errors="ignore")
returns an empty list instead of either
None
or an empty list, breaking theskip
compatibility.ISSUE TYPE
COMPONENT NAME
first_found
ANSIBLE VERSION
CONFIGURATION
n/a
OS / ENVIRONMENT
n/a
STEPS TO REPRODUCE
EXPECTED RESULTS
for both tasks
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: