From 7ee6d9e4e235769e91f8e5fee92cd32548f59c89 Mon Sep 17 00:00:00 2001 From: hrodmn Date: Tue, 26 Nov 2024 14:50:57 -0600 Subject: [PATCH] handle case with multiple values of same parameter like bands=B04&bands=B03&bands=B02 --- titiler/cmr/timeseries.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/titiler/cmr/timeseries.py b/titiler/cmr/timeseries.py index 0d7fb37..b014cf1 100644 --- a/titiler/cmr/timeseries.py +++ b/titiler/cmr/timeseries.py @@ -203,21 +203,25 @@ def build_request_urls( param_list: List[BaseModel], ): """Build lower-level request URLs from a base_url, a request, and a list of - additional query parameters + additional query parameters. Preserves multiple values for the same parameter. """ urls = [] - non_timeseries_params = { - key: value - for key, value in request.query_params.items() + + # Convert query_params to list of tuples, excluding timeseries fields + non_timeseries_params = [ + (key, value) + for key, value in request.query_params.multi_items() if key not in timeseries_field_names - } + ] + for _params in param_list: - request_params = { - **non_timeseries_params, - **_params.model_dump(), - } - url = f"{base_url}?{urlencode(request_params)}" - print(url) + model_params = [ + (str(key), str(value)) for key, value in _params.model_dump().items() + ] + + url = ( + f"{base_url}?{urlencode(non_timeseries_params + model_params, doseq=True)}" + ) urls.append(url) return urls