[
https://issues.apache.org/jira/browse/AMBARI-25997?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Viraj Jasani resolved AMBARI-25997.
-----------------------------------
Fix Version/s: 2.7.8
2.9.0
Resolution: Fixed
> Improvement and Bug Fix in ambari_server.properties.py
> ------------------------------------------------------
>
> Key: AMBARI-25997
> URL: https://issues.apache.org/jira/browse/AMBARI-25997
> Project: Ambari
> Issue Type: Bug
> Affects Versions: 2.8.0, 2.7.7
> Reporter: caijialiang
> Assignee: caijialiang
> Priority: Major
> Fix For: 2.7.8, 2.9.0
>
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> File Location: ambari-server/src/main/python/ambari_server/properties.py
> Problem Description:
> 1. The `__getattr__` method is used for dynamic proxying of methods. In the
> case where `hasattr(self._props, name)` is false indicating the corresponding
> method or attribute cannot be found, an exception needs to be thrown. If not,
> it may confuse the user and obstruct code debugging.
> 2. The class `Properties` proxies the `has_key` method to the `dict` object
> through `__getattr__`, which is acceptable: `Properties().has_key("x")`.
> However, for the operation `"x" in Properties()`, it ends up in an infinite
> hang, never returning. Therefore, a `__contains__` method needs to be
> implemented to keep consistency with the logic of `has_key`, i.e., to
> determine whether the object is in `_props`:
> ```python
> def __contains__(self, key):
> return key in self._props
> ```
> This modification prevents the infinite hang problem from occurring.
> To reproduce the hang issue, we can make a simplified version of the
> `Properties` class for testing, as follows:
> ```python
> #!/usr/bin/env python
> import os
> import re
> import time
> class Properties(object):
> def __init__(self, props=None):
> self._props = {}
> self._origprops = {}
> self._keymap = {}
> def get_property(self, key):
> return self._props.get(key, '')
> def propertyNames(self):
> return self._props.keys()
> def getPropertyDict(self):
> return self._props
> def __getitem__(self, name):
> return self.get_property(name)
> def __getattr__(self, name):
> try:
> return self.__dict__[name]
> except KeyError:
> if hasattr(self._props, name):
> return getattr(self._props, name)
> else:
> raise NotImplementedError("The method '{}' is not
> implemented.".format(name))
> def __contains__(self, key):
> return key in self._props
> if __name__ == "__main__":
> p = Properties()
> "a" in p
> ```
> Upon running this program with either Python 3 or Python 2 python, it will
> indefinitely hang, never returning.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]