There will be maintenance performed on,,, and starting at 9am PDT on Tuesday 18th August 2020. There will be an extremely small period of downtime at the start of the maintenance window as various services are restarted. Please address any comments, questions, or concerns to

rest: improve arg validation in gracedb.createSuperevent

parent 4fc8ddb6
......@@ -1157,7 +1157,7 @@ class GraceDb(GsiRest):
return self.get(uri).json()['numRows']
def createSuperevent(self, t_start, t_0, t_end, preferred_event,
category='production', events=[], labels=None):
category='production', events=None, labels=None):
"""Create a superevent.
All LIGO-Virgo users can create test superevents, but special
......@@ -1201,28 +1201,40 @@ class GraceDb(GsiRest):
if labels:
if isinstance(labels, six.string_types):
labels = [labels]
elif isinstance(labels, list):
elif isinstance(labels, (list, tuple)):
# Validate each entry
if any([not isinstance(l, six.string_types) for l in labels]):
err_msg = "One of the provided labels is not a string"
raise TypeError(err_msg)
raise TypeError("labels arg is {0}, should be str or list"
# Check labels against those in database
for l in labels:
if l not in self.allowed_labels:
raise NameError(("Label '{0}' does not exist in the "
raise ValueError(("Label '{0}' does not exist in the "
if events:
if isinstance(events, six.string_types):
events = [events]
elif isinstance(events, list):
elif isinstance(events, (list, tuple)):
if any([not isinstance(e, six.string_types) for e in events]):
err_msg = \
"One of the provided event graceids is not a string"
raise TypeError(err_msg)
raise TypeError("events arg is {0}, should be str or list"
# validate category, convert to short form if necessary
category = self._getCode(category.lower(),
# Validate category, convert to short form if necessary
if not isinstance(category, six.string_types):
err_msg = "category arg is {0}, should be a string".format(
raise TypeError(err_msg)
category = self._getCode(category, self.superevent_categories)
# Note: category can be None here as a result of processing
# by _getCode, which indicates failure to match the provided
# superevent category
if not category:
raise ValueError("category must be one of: {0}".format(
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment