Inventory Host class's `__repr__/__str__` can return None (TypeError) #24545
Comments
@movermeyer seems like a simple fix. Would you be interested in sending a bugfix PR? needs_info |
@movermeyer This issue is waiting for your response. Please respond or the issue will be closed. |
Sorry guys. I have neither the time nor inclination to provide a PR for this. |
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'. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
ISSUE TYPE
COMPONENT NAME
Ansible, inventory script
ANSIBLE VERSION
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 isNone
) from its__repr__
method. This is not allowed in Python.And yet, the Host
__init__
defaults the name toNone
, so this failure is actually the default case.The simplest possible example is probably:
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
The text was updated successfully, but these errors were encountered: