Skip to content

Commit 6ed5e38

Browse files
committed
fix: convert parameters eodag names of ValidationError messages to their STAC names
1 parent 4665cd1 commit 6ed5e38

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

eodag/api/product/metadata_mapping.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,8 @@ def _get_queryables(
14651465
# raise an error when a query param not allowed by the provider is found
14661466
if not isinstance(md_mapping, list) and raise_mtd_discovery_error:
14671467
raise ValidationError(
1468-
f"Search parameters which are not queryable are disallowed: {eodag_search_key}"
1468+
f"Search parameters which are not queryable are disallowed: {eodag_search_key}",
1469+
{eodag_search_key},
14691470
)
14701471
_, md_value = md_mapping
14711472
# query param from defined metadata_mapping

eodag/plugins/search/base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ def build_sort_by(
274274
if eodag_sort_order[:3] != "ASC" and eodag_sort_order[:3] != "DES":
275275
raise ValidationError(
276276
"Sorting order is invalid: it must be set to 'ASC' (ASCENDING) or "
277-
f"'DESC' (DESCENDING), got '{eodag_sort_order}' with '{eodag_sort_param}' instead"
277+
f"'DESC' (DESCENDING), got '{eodag_sort_order}' with '{eodag_sort_param}' instead",
278+
{eodag_sort_param},
278279
)
279280
eodag_sort_order = eodag_sort_order[:3]
280281

@@ -295,7 +296,7 @@ def build_sort_by(
295296
raise ValidationError(
296297
f"'{eodag_sort_param}' parameter is called several times to sort results with different "
297298
"sorting orders. Please set it to only one ('ASC' (ASCENDING) or 'DESC' (DESCENDING))",
298-
set([eodag_sort_param]),
299+
{eodag_sort_param},
299300
)
300301
provider_sort_by_tuples_used.append(provider_sort_by_tuple)
301302

eodag/plugins/search/build_search_result.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def discover_queryables(
597597
formated_kwargs[key] = kwargs[key]
598598
else:
599599
raise ValidationError(
600-
f"{key} is not a queryable parameter for {self.provider}"
600+
f"'{key}' is not a queryable parameter for {self.provider}", {key}
601601
)
602602

603603
# we use non empty kwargs as default to integrate user inputs
@@ -658,7 +658,9 @@ def discover_queryables(
658658
and keyword.replace("ecmwf:", "")
659659
not in set(list(available_values.keys()) + [f["name"] for f in form])
660660
):
661-
raise ValidationError(f"{keyword} is not a queryable parameter")
661+
raise ValidationError(
662+
f"'{keyword}' is not a queryable parameter", {keyword}
663+
)
662664

663665
# generate queryables
664666
if form:
@@ -745,7 +747,8 @@ def available_values_from_constraints(
745747
# we only compare list of strings.
746748
if isinstance(values, dict):
747749
raise ValidationError(
748-
f"Parameter value as object is not supported: {keyword}={values}"
750+
f"Parameter value as object is not supported: {keyword}={values}",
751+
{keyword},
749752
)
750753
filter_v = values if isinstance(values, (list, tuple)) else [values]
751754

@@ -810,7 +813,10 @@ def available_values_from_constraints(
810813
raise ValidationError(
811814
f"{keyword}={values} is not available"
812815
f"{all_keywords_str}."
813-
f" Allowed values are {', '.join(allowed_values)}."
816+
f" Allowed values are {', '.join(allowed_values)}.",
817+
set(
818+
[keyword] + [k for k in parsed_keywords if k in input_keywords]
819+
),
814820
)
815821

816822
parsed_keywords.append(keyword)

eodag/plugins/search/data_request_search.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ def _create_data_request(
370370
)
371371
raise ValidationError(
372372
f"Search parameters which are not queryable are disallowed for {product_type} with "
373-
f"{self.provider}: please remove '{not_queryable_search_param}' from your search parameters"
373+
f"{self.provider}: please remove '{not_queryable_search_param}' from your search parameters",
374+
{not_queryable_search_param},
374375
)
375376
logger.debug(
376377
f"Sending search job request to {url} with {str(request_body)}"

eodag/plugins/search/qssearch.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,8 @@ def build_query_string(
822822
)
823823
raise ValidationError(
824824
f"Search parameters which are not queryable are disallowed for {product_type} with "
825-
f"{self.provider}: please remove '{not_queryable_search_param}' from your search parameters"
825+
f"{self.provider}: please remove '{not_queryable_search_param}' from your search parameters",
826+
{not_queryable_search_param},
826827
)
827828

828829
# Build the final query string, in one go without quoting it
@@ -1876,7 +1877,8 @@ def build_query_string(
18761877
)
18771878
raise ValidationError(
18781879
f"Search parameters which are not queryable are disallowed for {product_type} with "
1879-
f"{self.provider}: please remove '{not_queryable_search_param}' from your search parameters"
1880+
f"{self.provider}: please remove '{not_queryable_search_param}' from your search parameters",
1881+
{not_queryable_search_param},
18801882
)
18811883

18821884
# Build the final query string, in one go without quoting it

eodag/rest/errors.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818
import logging
19+
import re
1920
from typing import Union
2021

2122
from fastapi import FastAPI, Request
@@ -89,10 +90,17 @@ def errors(self) -> list[dict[str, Union[str, int]]]:
8990

9091
if type(exception) is ValidationError:
9192
for error_param in exception.parameters:
92-
stac_param = EODAGSearch.to_stac(error_param)
93-
exception.message = exception.message.replace(
94-
error_param, stac_param
93+
error_param_pattern = rf"\b{error_param}\b"
94+
error_param_match = re.search(
95+
error_param_pattern, exception.message
9596
)
97+
if error_param_match:
98+
stac_param = EODAGSearch.to_stac(error_param)
99+
exception.message = re.sub(
100+
error_param_pattern,
101+
error_param_match.group(0).replace(error_param, stac_param),
102+
exception.message,
103+
)
96104
error_dict["message"] = exception.message
97105

98106
error_list.append(error_dict)

tests/units/test_search_plugins.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def test_plugins_search_querystringsearch_search_peps_ko(self):
422422
"Search parameters which are not queryable are disallowed for "
423423
f"{self.search_criteria_s2_msi_l1c['productType']} with {self.peps_search_plugin.provider}: "
424424
"please remove 'foo' from your search parameters",
425-
str(context.exception),
425+
context.exception.message,
426426
)
427427

428428
# restore the original config
@@ -451,7 +451,7 @@ def test_plugins_search_querystringsearch_search_peps_ko(self):
451451
"Search parameters which are not queryable are disallowed for "
452452
f"{self.search_criteria_s2_msi_l1c['productType']} with {self.peps_search_plugin.provider}: "
453453
"please remove 'foo' from your search parameters",
454-
str(context.exception),
454+
context.exception.message,
455455
)
456456

457457
# restore the original config
@@ -2624,8 +2624,8 @@ def test_plugins_search_ecmwfsearch_discover_queryables_ko(self, mock__fetch_dat
26242624
with self.assertRaises(ValidationError) as context:
26252625
self.search_plugin.discover_queryables(**params)
26262626
self.assertEqual(
2627-
f"{wrong_queryable} is not a queryable parameter for {self.provider}",
2628-
str(context.exception),
2627+
f"'{wrong_queryable}' is not a queryable parameter for {self.provider}",
2628+
context.exception.message,
26292629
)
26302630

26312631
@mock.patch("eodag.utils.requests.requests.sessions.Session.get", autospec=True)
@@ -3323,7 +3323,7 @@ def test_plugins_search_postjsonsearchwithstacqueryables_search_wekeomain_ko(sel
33233323
"Search parameters which are not queryable are disallowed for "
33243324
f"{self.search_criteria_s2_msi_l1c['productType']} with {self.wekeomain_search_plugin.provider}: "
33253325
"please remove 'foo' from your search parameters",
3326-
str(context.exception),
3326+
context.exception.message,
33273327
)
33283328

33293329
# restore the original config
@@ -3352,7 +3352,7 @@ def test_plugins_search_postjsonsearchwithstacqueryables_search_wekeomain_ko(sel
33523352
"Search parameters which are not queryable are disallowed for "
33533353
f"{self.search_criteria_s2_msi_l1c['productType']} with {self.wekeomain_search_plugin.provider}: "
33543354
"please remove 'foo' from your search parameters",
3355-
str(context.exception),
3355+
context.exception.message,
33563356
)
33573357

33583358
# restore the original config

0 commit comments

Comments
 (0)