Bug in implementation of ManageObject __eq__ method
Open
Nobody has claimed this yet.
needs verification
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 763
- PR merge metrics
- No merged PRs in 30d
Description
Hello.
In my opinion there is potentially a bug in ManagedObject class in eq.
Below is example code that will crash:
from pyVmomi.VmomiSupport import ManagedObject
mo = ManagedObject(moId="1")
if mo != None and mo != "":
print("Valid ManagedObject")
Output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyVmomi/VmomiSupport.py", line 479, in __ne__
return not(self == other)
File "pyVmomi/VmomiSupport.py", line 474, in __eq__
return self._moId == other._moId and \
AttributeError: 'str' object has no attribute '_moId'
Fixed code:
def __eq__(self, other):
if other is None:
return False
if not(isinstance(other, ManagedObject)):
return False
else:
return self._moId == other._moId and \
self.__class__ == other.__class__ and \
self._serverGuid == other._serverGuid
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pyVmomi/VmomiSupport.py at ManagedObject.eq and ne, using the reproduction in the issue to observe the AttributeError when comparing with a string. Verify that comparisons with None and non-ManagedObject values no longer raise, while ManagedObject comparisons still use the existing identity fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100