2828import attr
2929import cql2
3030import orjson
31- import pygeofilter
3231from fastapi import HTTPException
3332from pydantic import ValidationError
3433from pydantic_core import InitErrorDetails , PydanticCustomError
34+ from pygeofilter .parsers .cql2_json import parse as parse_json
3535from stac_fastapi .api .models import create_post_request_model
3636from stac_fastapi .types .errors import NotFoundError
3737from stac_fastapi .types .requests import get_base_url
@@ -481,10 +481,11 @@ def _clean_search_args(
481481 """Clean up search arguments to match format expected by pgstac"""
482482 if filter_expr :
483483 if filter_lang == "cql2-text" :
484- filter_expr = cql2 .parse_text (filter_expr ).to_json ()
485- filter_lang = "cql2-json"
486-
487- base_args ["filter" ] = str2json ("filter_expr" , filter_expr )
484+ base_args ["filter" ] = cql2 .parse_text (filter_expr ).to_json ()
485+ elif filter_lang == "cql2-json" :
486+ base_args ["filter" ] = str2json ("filter_expr" , filter_expr )
487+ else :
488+ raise HTTPException (status_code = 400 , detail = f"Unsupported filter_lang { filter_lang } " )
488489 base_args ["filter_lang" ] = "cql2-json"
489490
490491 if datetime :
@@ -501,10 +502,12 @@ def _clean_search_args(
501502 for sort in sortby :
502503 sortparts = re .match (r"^([+-]?)(.*)$" , sort )
503504 if sortparts :
504- sort_param .append ({
505- "field" : sortparts .group (2 ).strip (),
506- "direction" : "desc" if sortparts .group (1 ) == "-" else "asc" ,
507- })
505+ sort_param .append (
506+ {
507+ "field" : sortparts .group (2 ).strip (),
508+ "direction" : "desc" if sortparts .group (1 ) == "-" else "asc" ,
509+ }
510+ )
508511 base_args ["sortby" ] = sort_param
509512
510513 # Remove None values from dict
@@ -649,7 +652,7 @@ def add_error(error_message: str) -> None:
649652
650653 errors : list [InitErrorDetails ] = []
651654 try :
652- parsing_result = EodagEvaluator ().evaluate (pygeofilter . parse (filter_ )) # type: ignore
655+ parsing_result = EodagEvaluator ().evaluate (parse_json (filter_ )) # type: ignore
653656 except (ValueError , NotImplementedError ) as e :
654657 add_error (str (e ))
655658 raise ValidationError .from_exception_data (title = "stac-fastapi-eodag" , line_errors = errors ) from e
0 commit comments