From 4bfd59b5e54a0848c7a2b591a7ce0f08555dbcc0 Mon Sep 17 00:00:00 2001 From: Josef Skladanka Date: Nov 19 2018 09:17:34 +0000 Subject: Fix ImmutableMultiDict handling for python 3.7 For some reason, in python 3.7 `dict()`-call over ImmutableMultiDict structure from Werkzeug behaves differently. In the previous versions a dict of lists is created (thus representing all the values given to the specific URL-encoded query parameter), py37 only creates a dict containing the first value in string form. This patch makes sure the ImmutableMultiDict is converted to a dict-of-lists in a foolproof fashion. --- diff --git a/resultsdb/controllers/api_v2.py b/resultsdb/controllers/api_v2.py index d4afbb8..ffce47c 100644 --- a/resultsdb/controllers/api_v2.py +++ b/resultsdb/controllers/api_v2.py @@ -420,12 +420,12 @@ def __get_results_parse_args(): retval['args'] = args # find results_data with the query parameters - # these are the paramters other than those defined in RequestParser - req_args = dict(request.args) # this is important, do not delete ;) - - # req_args is a dict of lists, where keys are param names and values are param values - # the value is a list even if only one param value was specified - results_data = {key: req_args[key] for key in req_args.keys() if key not in args} + # these are the paramters other than those defined in RequestParser + # request.args is a ImmutableMultiDict, which allows for more values to be + # stored in one key (so one can do stuff like .../results?item=foo&item=bar in URL). + # Here we transform the `request.args` MultiDict to `results_data` dict of lists, and + # while also filtering out the reserved-keyword-args + results_data = {k: request.args.getlist(k) for k in request.args.keys() if k not in args} for param, values in results_data.items(): for i, value in enumerate(values): results_data[param][i] = value.split(',')