Skip to content

Commit 6dafde9

Browse files
committed
Address review comments for 404 instead of assert
1 parent 14d8fa2 commit 6dafde9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lnt/server/ui/views.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ def ts_data(ts):
188188

189189
def determine_aggregation_function(function_name):
190190
"""
191-
Return the aggregation function associated to the provided function name. This is used by
192-
dropdown menus that allow selecting from multiple aggregation functions.
191+
Return the aggregation function associated to the provided function name, or None if
192+
the function name is unsupported.
193+
194+
This is used by dropdown menus that allow selecting from multiple aggregation functions.
193195
"""
194196
if function_name == 'min':
195197
return lnt.util.stats.safe_min
@@ -200,7 +202,7 @@ def determine_aggregation_function(function_name):
200202
elif function_name == 'median':
201203
return lnt.util.stats.median
202204
else:
203-
assert False, f'Invalid aggregation function name {function_name}'
205+
return None
204206

205207

206208
@db_route('/submitRun', methods=('GET', 'POST'))
@@ -370,7 +372,10 @@ def __init__(self, run_id):
370372
abort(404, "Invalid run id {}".format(run_id))
371373

372374
# Get the aggregation function to use.
373-
aggregation_fn = determine_aggregation_function(request.args.get('aggregation_function', 'min'))
375+
fn_name = request.args.get('aggregation_function', 'min')
376+
aggregation_fn = determine_aggregation_function(fn_name)
377+
if aggregation_fn is None:
378+
abort(404, "Invalid aggregation function name {}".format(fn_name))
374379

375380
# Get the MW confidence level.
376381
try:
@@ -1197,6 +1202,8 @@ def trace_name(name, test_name, field_name):
11971202

11981203
fn_name = options.get('aggregation_function') or ('max' if field.bigger_is_better else 'min')
11991204
aggregation_fn = determine_aggregation_function(fn_name)
1205+
if aggregation_fn is None:
1206+
abort(404, "Invalid aggregation function name {}".format(fn_name))
12001207
agg_value = aggregation_fn(values)
12011208

12021209
# When aggregating multiple samples, it becomes unclear which sample to use for

tests/server/ui/V4Pages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ def main():
640640
check_json(client, '/db_default/v4/nts/graph?aggregation_function=mean&plot.0=1.3.2&json=true&submit=Update')
641641
check_html(client, '/db_default/v4/nts/graph?aggregation_function=mean&plot.0=1.3.2')
642642
check_json(client, '/db_default/v4/nts/graph?aggregation_function=mean&plot.0=1.3.2&json=true')
643+
check_html(client, '/db_default/v4/nts/graph?aggregation_function=nonexistent&plot.0=1.3.2', expected_code=404)
643644
app.testing = False
644645
error_page = check_html(client, '/explode', expected_code=500)
645646
assert re.search("division (or modulo )?by zero",

0 commit comments

Comments
 (0)