Skip to content

Commit

Permalink
Merge pull request #4561 from zenoss/bugfix/ZEN-35063.7x
Browse files Browse the repository at this point in the history
Add error handling when iterating over the content of a relation.
  • Loading branch information
jpeacock-zenoss authored Sep 19, 2024
2 parents ad30c45 + 7dd7c09 commit 21a363f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Products/ZenRelations/ToManyContRelationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,28 @@ def objectValues(self, spec=None):

def objectValuesGen(self):
"""Generator that returns all related objects."""
return (obj.__of__(self) for obj in self._objects.values())
for obj in self._objects.values():
try:
yield obj.__of__(self)
except Exception:
# If the object does not have an `__of__` method, don't
# trust that it has an `getPrimaryId` method. So,
# use `getPrimaryId` if it exists, otherwise, use the
# type of the object itself.
if hasattr(obj, "getPrimaryId"):
key = "primary-id"
value = obj.getPrimaryId()
else:
# Getting the type of an object that's been wrapped
# in an aquisition wrapper isn't helpful, so unwrap
# it first, but don't trust that `aq_base` will
# succeed.
key = "type"
try:
value = type(aq_base(obj))
except Exception:
value = type(obj)
log.exception("failed to wrap object %s=%s", key, value)

def objectItems(self, spec=None):
"""over ride to only return owned objects for many to many rel"""
Expand Down

0 comments on commit 21a363f

Please sign in to comment.