diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ef5ec..67ec2c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Aria stacking uses aria frame id instead of frame number for stacking - asf_search uses `SearchAPISession` by default for search queries - bump asf-search to v9.0.4 +- increase search query limit to 2000, raise error if expected output is over that number ------ ## [1.0.4](https://github.com/asfadmin/Discovery-SearchAPI-v3/compare/v1.0.3...v1.0.4) diff --git a/src/SearchAPI/application/asf_opts.py b/src/SearchAPI/application/asf_opts.py index 158d042..ccf7313 100644 --- a/src/SearchAPI/application/asf_opts.py +++ b/src/SearchAPI/application/asf_opts.py @@ -147,7 +147,7 @@ async def get_body(request: Request): return {} -async def process_search_request(request: Request) -> SearchOptsModel: +async def process_search_request(request: Request, is_baseline: bool = False) -> SearchOptsModel: """ Extracts the request's query+body params, returns ASFSearchOptions, request method, output format, and a dictionary of the merged request args wrapped in a pydantic model (SearchOptsModel) @@ -177,13 +177,25 @@ async def process_search_request(request: Request) -> SearchOptsModel: try: # we are no longer allowing unbounded searches - if query_opts.granule_list is None and query_opts.product_list is None: + if ( + query_opts.granule_list is None + and query_opts.product_list is None + and output not in ['python', 'count'] + and not is_baseline + ): if query_opts.maxResults is None: - query_opts.maxResults = asf.search_count(opts=query_opts) + maxResults = asf.search_count(opts=query_opts) + if maxResults > 2000: + raise ValueError( + ( + 'SearchAPI no longer supports unbounded searches with expected results over 2000, ' + 'please use the asf-search python module for long-lived searches or set `maxResults` to 2000 or less. ' + 'To have SearchAPI automatically generate a python script for the equivalent search to your SearchAPI query ' + 'set `output=python`' + ) + ) elif query_opts.maxResults <= 0: - raise ValueError(f'Search keyword "maxResults" must be greater than 0') - - query_opts.maxResults = min(1500, query_opts.maxResults) + raise ValueError('Search keyword "maxResults" must be greater than 0') searchOpts = SearchOptsModel(opts=query_opts, output=output, merged_args=merged_args, request_method=request.method) except (ValueError, ValidationError) as exc: @@ -194,7 +206,7 @@ async def process_search_request(request: Request) -> SearchOptsModel: async def process_baseline_request(request: Request) -> BaselineSearchOptsModel: """Processes request to baseline endpoint""" - searchOpts = await process_search_request(request=request) + searchOpts = await process_search_request(request=request, is_baseline=True) reference = searchOpts.merged_args.get('reference') try: baselineSearchOpts = BaselineSearchOptsModel(**searchOpts.model_dump(), reference=reference)