'%s' object has no attribute '%s'
Package:
ansible
49704

Exception Class:
AttributeError
Raise code
display = Display()
def _generic_g(prop_name, self):
try:
value = self._attributes[prop_name]
except KeyError:
raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, prop_name))
if value is Sentinel:
value = self._attr_defaults[prop_name]
return value
Links to the raise (3)
https://github.com/ansible/ansible/blob/015331518dff60f31a7d8ce24fc315e3ac9e86f8/lib/ansible/playbook/base.py#L36 https://github.com/ansible/ansible/blob/015331518dff60f31a7d8ce24fc315e3ac9e86f8/lib/ansible/playbook/base.py#L51 https://github.com/ansible/ansible/blob/015331518dff60f31a7d8ce24fc315e3ac9e86f8/lib/ansible/playbook/base.py#L64See also in the other packages (5)
(❌️ No answer)
mlflow/s-object-has-no-attribute-s/
(❌️ No answer)
sympy/s-object-has-no-attribute-s/
(❌️ No answer)
statsmodels/s-object-has-no-attribute-s/
(❌️ No answer)
dm-sonnet/s-object-has-no-attribute-s/
(❌️ No answer)
pywin32/s-object-has-no-attribute-s/
Ways to fix
Summary:
This exception is thrown when the _generic_g function is called from ansible. The function takes in two parameters: prop_name and self. prop_name is a string and self is an instance of an object. The object passed in must have an _attributes dictionary where one of the keys is the value passed into prop_name, otherwise, the exception will be thrown.
Code to Reproduce the Error (Wrong):
from ansible.playbook.base import _generic_g
class A():
_attributes = {"key":"val"}
a = A()
_generic_g("random", a)
Error Message:
KeyError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/ansible/playbook/base.py in _generic_g(prop_name, self) 32 try: ---> 33 value = self._attributes[prop_name] 34 except KeyError: KeyError: 'random' During handling of the above exception, another exception occurred: AttributeError Traceback (most recent call last) 1 frames /usr/local/lib/python3.7/dist-packages/ansible/playbook/base.py in _generic_g(prop_name, self) 33 value = self._attributes[prop_name] 34 except KeyError: ---> 35 raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, prop_name)) 36 37 if value is Sentinel: AttributeError: 'A' object has no attribute 'random'
Working Version (Right):
from ansible.playbook.base import _generic_g
class A():
_attributes = {"key":"val"}
a = A()
_generic_g("key", a)
Add a possible fix
Please authorize to post fix