Commit e14a424e authored by Tanner Prestegard's avatar Tanner Prestegard

Fix cases where arguments are checked for truthiness

Fix several cases where we check 'if arg'; instead should be
'if arg is not None' since the original can fail when arg is
numeric and zero-valued. Specific case we are fixing is for
ProbHasNS and ProbHasRemnant in createVOEvent, but we fix
a few others, too.
parent fd92d039
......@@ -681,7 +681,7 @@ class GraceDb(GsiRest):
uri = self.links['events']
qdict = {}
if query: qdict['query'] = query
if count: qdict['count'] = count
if count is not None: qdict['count'] = count
if orderby: qdict['sort'] = orderby
if columns: qdict['columns'] = columns
if qdict:
......@@ -820,13 +820,13 @@ class GraceDb(GsiRest):
'preferred_event')
request_body = {}
if t_start:
if t_start is not None:
request_body['t_start'] = t_start
if t_0:
if t_0 is not None:
request_body['t_0'] = t_0
if t_end:
if t_end is not None:
request_body['t_end'] = t_end
if preferred_event:
if preferred_event is not None:
request_body['preferred_event'] = preferred_event
template = self.templates['superevent-detail-template']
uri = template.format(superevent_id=superevent_id)
......@@ -937,7 +937,7 @@ class GraceDb(GsiRest):
# Compile URL parameters
qdict = {}
if query: qdict['query'] = query
if count: qdict['count'] = count
if count is not None: qdict['count'] = count
if orderby: qdict['sort'] = orderby
if qdict:
uri += "?" + urlencode(qdict)
......@@ -1075,7 +1075,7 @@ class GraceDb(GsiRest):
>>> g = GraceDb()
>>> log_info = g.logs('T101383', 10).json()
"""
if log_number and not isinstance(log_number, int):
if log_number is not None and not isinstance(log_number, int):
raise TypeError('log_number should be an int')
# Set up template and object id
......@@ -1093,7 +1093,7 @@ class GraceDb(GsiRest):
else:
template = self.templates['event-log-template']
if log_number:
if log_number is not None:
uri_kwargs['N'] = log_number
uri = template.format(**uri_kwargs)
......@@ -1307,7 +1307,7 @@ class GraceDb(GsiRest):
else:
template = self.templates['emobservation-list-template']
if emobservation_num:
if emobservation_num is not None:
uri_kwargs['N'] = emobservation_num
uri = template.format(**uri_kwargs)
......@@ -1669,7 +1669,7 @@ class GraceDb(GsiRest):
else:
template = self.templates['voevent-list-template']
if voevent_num:
if voevent_num is not None:
uri_kwargs['N'] = voevent_num
uri = template.format(**uri_kwargs)
......@@ -1751,15 +1751,15 @@ class GraceDb(GsiRest):
'CoincComment': CoincComment
}
# Add optional args
if skymap_type:
if skymap_type is not None:
body['skymap_type'] = skymap_type
if skymap_filename:
if skymap_filename is not None:
body['skymap_filename'] = skymap_filename
if skymap_image_filename:
if skymap_image_filename is not None:
body['skymap_image_filename'] = skymap_image_filename
if ProbHasNS:
if ProbHasNS is not None:
body['ProbHasNS'] = ProbHasNS
if ProbHasRemnant:
if ProbHasRemnant is not None:
body['ProbHasRemnant'] = ProbHasRemnant
return self.post(uri, body=body)
......@@ -1864,13 +1864,13 @@ class GraceDb(GsiRest):
elif (action == 'update'):
http_method = "PATCH"
uri_kwargs['typeinst'] = signoff_type + instrument
if comment:
if comment is not None:
body['comment'] = comment
if status:
if status is not None:
body['status'] = status
elif (action == 'get'):
http_method = "GET"
if signoff_type:
if signoff_type is not None:
uri_kwargs['typeinst'] = signoff_type + instrument
elif (action == 'delete'):
http_method = "DELETE"
......@@ -1911,7 +1911,7 @@ class GraceDb(GsiRest):
# Get URI template
is_superevent = kwargs.pop('is_superevent', False)
if is_superevent:
if signoff_type:
if signoff_type is not None:
template = self.templates['superevent-signoff-detail-template']
else:
template = self.templates['superevent-signoff-list-template']
......
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