fix coreapi exception on MonitoringService MonitoringPublisher
Change-Id: If17213209564709b243536aca60f704217daa1cb
diff --git a/xos/coreapi/apihelper.py b/xos/coreapi/apihelper.py
index 3ef547f..b69ea72 100644
--- a/xos/coreapi/apihelper.py
+++ b/xos/coreapi/apihelper.py
@@ -85,11 +85,24 @@
continue
if "+" in related_name:
continue
- rel_objs = getattr(obj, related_name)
+ try:
+ rel_objs = getattr(obj, related_name)
+ except Exception, e:
+ # django makes catching this exception unnecessarily difficult
+ if type(e).__name__ == "RelatedObjectDoesNotExist":
+ # OneToOneField throws this if relation does not exist
+ continue
+ else:
+ raise
+
+ if not hasattr(rel_objs, "all"):
+ # this is in anticipation of OneToOneField causing problems
+ continue
+
for rel_obj in rel_objs.all():
if not hasattr(p_obj,related_name+"_ids"):
continue
- x=getattr(p_obj,related_name+"_ids").append(rel_obj.id)
+ getattr(p_obj,related_name+"_ids").append(rel_obj.id)
# Generate a list of class names for the object. This includes its
# ancestors. Anything that is a descendant of PlCoreBase or User