vmware / vmware/pyvmomi

Bug in implementation of ManageObject __eq__ method

Open
#655 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.