hasattr throws wrong exception when using python3.4
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Magnum |
Fix Released
|
Medium
|
Yang Hongyang |
Bug Description
Magnum python34 test fails with:
2016-02-29 16:15:58.511 | magnum.
2016-02-29 16:15:58.511 | -------
2016-02-29 16:15:58.511 |
2016-02-29 16:15:58.511 | Captured traceback:
2016-02-29 16:15:58.511 | ~~~~~~~~~~~~~~~~~~~
2016-02-29 16:15:58.511 | b'Traceback (most recent call last):'
2016-02-29 16:15:58.511 | b' File "/home/
2016-02-29 16:15:58.511 | b" op='remove')"
2016-02-29 16:15:58.511 | b' File "/home/
2016-02-29 16:15:58.511 | b' return func(*args, **keywargs)'
2016-02-29 16:15:58.512 | b' File "/home/
2016-02-29 16:15:58.512 | b' test(self, baymodel_ident, patch)'
2016-02-29 16:15:58.512 | b' File "<decorator-
2016-02-29 16:15:58.512 | b' File "/home/
2016-02-29 16:15:58.512 | b' baymodel_dict = api_utils.
2016-02-29 16:15:58.512 | b' File "/home/
2016-02-29 16:15:58.512 | b' for k in self.fields'
2016-02-29 16:15:58.512 | b' File "/home/
2016-02-29 16:15:58.512 | b' if hasattr(self, k)}'
2016-02-29 16:15:58.512 | b' File "/home/
2016-02-29 16:15:58.512 | b' self.obj_
2016-02-29 16:15:58.513 | b' File "/home/
2016-02-29 16:15:58.513 | b' _("Cannot load \'%s\' in the base class") % attrname)'
2016-02-29 16:15:58.513 | b"NotImplemente
2016-02-29 16:15:58.513 | b''
This is because we use hasattr() to generate attr dict for an object, the oslo_versionedo
https:/
hasattr(object, name)
The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an exception or not.)
But it will fail on python3 because in python3 it checks getattr() raises an AttributeError or not:
https:/
hasattr(object, name)
The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.)
affects: | magnum → oslo.versionedobjects |
Changed in oslo.versionedobjects: | |
assignee: | nobody → Yang Hongyang (hongyang-yang) |
affects: | oslo.versionedobjects → magnum |
Being fixed in https:/ /review. openstack. org/#/c/ 285647/ right?