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

Comments

Projects
None yet
5 participants
@movermeyer
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)
@jctanner

This comment has been minimized.

Member

jctanner commented May 12, 2017

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

needs_info

@ansibot

This comment has been minimized.

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

This comment has been minimized.

Contributor

movermeyer commented Jan 31, 2018

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

@ansibot ansibot removed the needs_info label Jan 31, 2018

@ansibot ansibot added bug and removed bug_report labels Mar 1, 2018

@ansibot ansibot added the traceback label May 28, 2018

@bcoca

This comment has been minimized.

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 Nov 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment