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

Inventory Host class's __repr__/__str__ can return None (TypeError) #24545

Closed
movermeyer opened this issue May 12, 2017 · 4 comments
Closed

Inventory Host class's __repr__/__str__ can return None (TypeError) #24545

movermeyer opened this issue May 12, 2017 · 4 comments
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. c:inventory/contrib_script inventory Inventory category support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@movermeyer
Copy link
Contributor

movermeyer commented May 12, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Ansible, inventory script

ANSIBLE VERSION
ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
CONFIGURATION

No changes to ansible.cfg

OS / ENVIRONMENT

N/A

SUMMARY

Ansible's Inventory Host class's __repr__/__str__ can return None. This is not allowed in Python and raises TypeError.

STEPS TO REPRODUCE

I was using the Cobbler inventory script and it created an Ansible Host object that had no hostname. This alone is unexpected (seems to be a bug in the Cobbler inventory script (#24546)), but that is not what this issue is about. While trying to debug the problem, I tried to print out the host that was having issues. However even just printing the object was causing Python to crash.

This is a result of Host object returning just self.name (which is None) from its __repr__ method. This is not allowed in Python.
And yet, the Host __init__ defaults the name to None, so this failure is actually the default case.

The simplest possible example is probably:

from ansible.inventory.host import Host
print Host()
EXPECTED RESULTS

I would expect it to print a string representation of the Host, (perhaps something like "Host:{self.name}") instead of crashing Python.

ACTUAL RESULTS
python test.py
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    print Host()
TypeError: __str__ returned non-string (type NoneType)
@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report needs_triage Needs a first human triage before being processed. labels May 12, 2017
@jctanner jctanner added c:inventory/contrib_script and removed needs_triage Needs a first human triage before being processed. labels May 12, 2017
@jctanner
Copy link
Contributor

@movermeyer seems like a simple fix. Would you be interested in sending a bugfix PR?

needs_info

@ansibot ansibot added the needs_info This issue requires further information. Please answer any outstanding questions. label May 12, 2017
movermeyer added a commit to movermeyer/ansible that referenced this issue May 12, 2017
@alikins alikins added the inventory Inventory category label May 24, 2017
@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 1, 2017
@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Nov 21, 2017
@ansibot
Copy link
Contributor

ansibot commented Jan 31, 2018

@movermeyer This issue is waiting for your response. Please respond or the issue will be closed.

click here for bot help

@movermeyer
Copy link
Contributor Author

Sorry guys. I have neither the time nor inclination to provide a PR for this.

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Jan 31, 2018
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@ansibot ansibot added the traceback This issue/PR includes a traceback. label May 28, 2018
@bcoca
Copy link
Member

bcoca commented Nov 16, 2018

Since this is not an issue that affects our current code but the utilization of private methods by 3rd party not providing needed information to the objects, I'm going to close this issue as 'not a bug'.

@bcoca bcoca closed this as completed Nov 16, 2018
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. c:inventory/contrib_script inventory Inventory category support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants