Skip to content
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

Flatten field yields unexpected results when it hits None #69012

Open
borisovano opened this issue Apr 17, 2020 · 4 comments · May be fixed by #69013 or #70141
Open

Flatten field yields unexpected results when it hits None #69012

borisovano opened this issue Apr 17, 2020 · 4 comments · May be fixed by #69013 or #70141

Comments

@borisovano
Copy link

@borisovano borisovano commented Apr 17, 2020

SUMMARY

Flatten field yields unexpected results when it hits None. Instead of skipping over none it silently discards the to-be-flatten list. See example below.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

flatten filter

ANSIBLE VERSION
ansible 2.8.1
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Apr  8 2019, 18:17:52) [GCC 8.3.0]
OS / ENVIRONMENT

FROM pad92/ansible-alpine:latest

STEPS TO REPRODUCE
- hosts: localhost
  vars:
    nested_a:
      - "a"
      - "b"
      - ["c","d"]

    nested_b:
      - ["a", None, "b"]
      - "c"
      - "d"

  tasks:
    - name: Works 
      debug:
        msg: "Flatten list: {{ nested_a | flatten }}"

    - name: Where is 'b'
      debug:
        msg: "Flatten list: {{ nested_b | flatten }}"
EXPECTED RESULTS

ok: [localhost] => {
"msg": "Flatten list: ['a', 'b', 'c', 'd']"
}

TASK [WTF is 'b'] ************************************************************************************************************
ok: [localhost] => {
"msg": "Flatten list: ['a', 'b', 'c', 'd']' <--------- 'b' is present
}

ACTUAL RESULTS

ok: [localhost] => {
"msg": "Flatten list: ['a', 'b', 'c', 'd']"
}

TASK [where is 'b'] ************************************************************************************************************
ok: [localhost] => {
"msg": "Flatten list: ['a', 'c', 'd']" <--------- 'b' is missing
}

@sivel
Copy link
Member

@sivel sivel commented Apr 17, 2020

It looks like the issue is with this part of the code:

if element in (None, 'None', 'null'):
# ignore undefined items
break

That break should be a continue.

@sivel sivel added the easyfix label Apr 17, 2020
borisovano added a commit to borisovano/ansible that referenced this issue Apr 17, 2020
fix issue ansible#69012
@borisovano
Copy link
Author

@borisovano borisovano commented Apr 17, 2020

@sivel yes so it looks.
(I was using locally patched version for few days until my conscience nagging got too loud)

#69013

ps - thanks for the quick triage :)

@Akasurde
Copy link
Member

@Akasurde Akasurde commented Jun 18, 2020

resolved_by_pr #69013

@Akasurde
Copy link
Member

@Akasurde Akasurde commented Jun 18, 2020

@borisovano, Could you please check PR #69013 and let us know if it works for you ?

Thanks.

needs_info

@Akasurde Akasurde removed the needs_triage label Jun 18, 2020
@ansibot ansibot added the needs_info label Jun 18, 2020
bcoca added a commit to bcoca/ansible that referenced this issue Jun 18, 2020
bcoca added a commit to bcoca/ansible that referenced this issue Jun 18, 2020
@bcoca bcoca linked a pull request that will close this issue Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.