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

DigitalOcean Inventory: Removed sort from json dump #34217

Merged
merged 1 commit into from
Feb 10, 2018

Conversation

BondAnthony
Copy link
Contributor

SUMMARY

Remove sort_keys from json.dumps since the resulting keys are strings and integers. Currently this works without an issues when using python 2. When running the same code under python3 the inventory script is unable to complete successfully because key sorting is attempting to sort a string against an integer.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

contrib/inventory/digital_ocean.py

ANSIBLE VERSION
ansible 2.5.0 (test/block-storage ee4235019f) last updated 2017/12/22 17:09:40 (GMT -400)
  config file = /Users/abond/Dev/github/ansible.cfg
  configured module search path = ['/Users/abond/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/abond/Dev/github/ansible/lib/ansible
  executable location = /Users/abond/Dev/github/ansible/bin/ansible
  python version = 3.6.4 (default, Dec 19 2017, 15:24:51) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
ADDITIONAL INFORMATION
/usr/local/bin/python3 /Users/abond/Dev/github/ansible/contrib/inventory/digital_ocean.py --pretty
Traceback (most recent call last):
  File "/Users/abond/Dev/github/ansible/contrib/inventory/digital_ocean.py", line 543, in <module>
    DigitalOceanInventory()
  File "/Users/abond/Dev/github/ansible/contrib/inventory/digital_ocean.py", line 313, in __init__
    self.write_to_cache()
  File "/Users/abond/Dev/github/ansible/contrib/inventory/digital_ocean.py", line 519, in write_to_cache
    json_data = json.dumps(data, sort_keys=True, indent=2)
  File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 430, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
    yield from chunks
  File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 353, in _iterencode_dict
    items = sorted(dct.items(), key=lambda kv: kv[0])
TypeError: '<' not supported between instances of 'int' and 'str'

After removing sort_keys=True the inventory script will respond accordingly.

@BondAnthony BondAnthony changed the title Removed sort from json dump DigitalOcean Inventory: Removed sort from json dump Dec 24, 2017
@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bugfix_pull_request c:inventory/contrib_script cloud digital_ocean inventory Inventory category needs_triage Needs a first human triage before being processed. python3 support:community This issue/PR relates to code supported by the Ansible community. labels Dec 24, 2017
@Akasurde Akasurde removed the needs_triage Needs a first human triage before being processed. label Dec 25, 2017
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jan 2, 2018
@Akasurde
Copy link
Member

rebuild_merge

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Feb 10, 2018
@Akasurde Akasurde merged commit 2940b9d into ansible:devel Feb 10, 2018
@Akasurde
Copy link
Member

@BondAnthony Thanks for your contribution.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. c:inventory/contrib_script cloud digital_ocean inventory Inventory category python3 support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants