From 08968fa3fbae0b3851d142ba5cdb30ad593aef4e Mon Sep 17 00:00:00 2001 From: Vincent Privat Date: Fri, 29 Nov 2024 16:04:23 +0100 Subject: [PATCH] fix errors when search returns no body --- src/stac_api_validator/validations.py | 37 ++++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/stac_api_validator/validations.py b/src/stac_api_validator/validations.py index 5b59351..04325f9 100644 --- a/src/stac_api_validator/validations.py +++ b/src/stac_api_validator/validations.py @@ -3199,23 +3199,24 @@ def validate_item_search_ids( r_session=r_session, ) - items = body.get("features") # type: ignore - if items and len(items) >= 2: - _validate_search_ids_with_ids( - search_url, [items[0].get("id")], methods, errors, r_session - ) - _validate_search_ids_with_ids( - search_url, - [items[0].get("id"), items[1].get("id")], - methods, - errors, - r_session, - ) - _validate_search_ids_with_ids( - search_url, [i["id"] for i in items], methods, errors, r_session - ) - else: - warnings += f"[{Context.ITEM_SEARCH}] GET Search with no parameters returned < 2 results" + if body: + items = body.get("features") # type: ignore + if items and len(items) >= 2: + _validate_search_ids_with_ids( + search_url, [items[0].get("id")], methods, errors, r_session + ) + _validate_search_ids_with_ids( + search_url, + [items[0].get("id"), items[1].get("id")], + methods, + errors, + r_session, + ) + _validate_search_ids_with_ids( + search_url, [i["id"] for i in items], methods, errors, r_session + ) + else: + warnings += f"[{Context.ITEM_SEARCH}] GET Search with no parameters returned < 2 results" def validate_item_search_ids_does_not_override_all_other_params( @@ -3236,7 +3237,7 @@ def validate_item_search_ids_does_not_override_all_other_params( content_type=geojson_mt, r_session=r_session, ) - if body.get("features"): # type: ignore + if body and body.get("features"): # type: ignore _validate_search_ids_with_ids_no_override( search_url, body["features"][0],