From a129d870dbfd3d5c9b558e0d40d2fc79cac30c3c Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Wed, 1 Aug 2018 10:58:38 -0500
Subject: [PATCH] Bugfix for superevent VOEvents

Since we use the preferred event to construct much of the VOEvent
for a superevent, we have to select the event's subclass (note that this
is done for events by the event_and_auth_required decorator, which calls
Event.getByGraceid).  This was preventing certain subclass-specific
attributes from being added to the VOEvents, like ProbHasNS,
ProbHasRemnant, etc.
---
 gracedb/superevents/buildVOEvent.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gracedb/superevents/buildVOEvent.py b/gracedb/superevents/buildVOEvent.py
index cb6fcd805..6400e5584 100644
--- a/gracedb/superevents/buildVOEvent.py
+++ b/gracedb/superevents/buildVOEvent.py
@@ -51,6 +51,15 @@ def construct_voevent_file(superevent, voevent, request=None,
 
     # Set preferred_event as event to be used in most of this
     event = superevent.preferred_event
+    # Get the event subclass (CoincInspiralEvent, MultiBurstEvent, etc.) and
+    # set that as the event
+    subclass_fields = [f for f in event.__class__._meta.get_fields()
+        if (f.one_to_one and f.auto_created and not f.concrete and
+            event.__class__ in f.related_model.__bases__)]
+    for f in subclass_fields:
+        if hasattr(event, f.name):
+            event = getattr(event, f.name)
+            break
 
     # Let's convert that voevent_type to something nicer looking
     voevent_type = VOEVENT_TYPE_DICT[voevent.voevent_type]
-- 
GitLab