Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

fix ''dict object has no attribute dict_keys" issue with python3 #578

Merged
merged 4 commits into from
Jun 7, 2019

Conversation

jmlrt
Copy link
Member

@jmlrt jmlrt commented Jun 6, 2019

In Python2, the dict.keys(), dict.values(), and dict.items() methods returns a list. Jinja2 returns that to Ansible via a string representation that Ansible can turn back into a list. In Python3, those methods return a dictionary view object.
resource: https://docs.ansible.com/ansible/2.4/playbooks_python_version.html#dictionary-views

Fix #570

jmlrt and others added 2 commits June 6, 2019 18:45
In Python2, the dict.keys(), dict.values(), and dict.items() methods returns a list. Jinja2 returns that to Ansible via a string representation that Ansible can turn back into a list. In Python3, those methods return a dictionary view object.
resource: https://docs.ansible.com/ansible/2.4/playbooks_python_version.html#dictionary-views
@jmlrt jmlrt requested review from Crazybus and itsmed June 6, 2019 16:48
@jmlrt jmlrt self-assigned this Jun 6, 2019
@jmlrt jmlrt added the bug label Jun 6, 2019
@@ -1,6 +1,6 @@
---
- name: set fact manage_file_users
set_fact: manage_file_users=es_users is defined and es_users.file is defined and es_users.file.keys() | length > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are some of these now .keys() | list while others are just list with the .keys() also removed? I can't figure out why some still need .keys() and some don't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a mistake => fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a few more were it was removed. Which is why I thought it was on purpose. At least 2 more in this PR where it was deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? I don't see no more | list without .keys()

@jmlrt jmlrt requested a review from Crazybus June 7, 2019 13:35
Copy link
Contributor

@Crazybus Crazybus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jmlrt jmlrt merged commit 5b1d028 into elastic:master Jun 7, 2019
@jmlrt jmlrt deleted the 570-fix-python3-dict-keys branch June 7, 2019 13:55
@svanschalkwyk
Copy link

Thanks! Quick turn-around!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python3 "'dict object' has no attribute \"dict_keys(['... "
3 participants