Skip to content

Commit 6b51b99

Browse files
Merge pull request #47 from asfadmin/dev
Unbounded Non-List Param Search Results exceeding 2000 Now Raises Error
2 parents 668804b + 0a49ea2 commit 6b51b99

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
3535
- Aria stacking uses aria frame id instead of frame number for stacking
3636
- asf_search uses `SearchAPISession` by default for search queries
3737
- bump asf-search to v9.0.4
38+
- increase search query limit to 2000, raise error if expected output is over that number
3839

3940
------
4041
## [1.0.4](https://github.com/asfadmin/Discovery-SearchAPI-v3/compare/v1.0.3...v1.0.4)

src/SearchAPI/application/asf_opts.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def get_body(request: Request):
147147
return {}
148148

149149

150-
async def process_search_request(request: Request) -> SearchOptsModel:
150+
async def process_search_request(request: Request, is_baseline: bool = False) -> SearchOptsModel:
151151
"""
152152
Extracts the request's query+body params, returns ASFSearchOptions, request method, output format, and a dictionary
153153
of the merged request args wrapped in a pydantic model (SearchOptsModel)
@@ -177,13 +177,25 @@ async def process_search_request(request: Request) -> SearchOptsModel:
177177

178178
try:
179179
# we are no longer allowing unbounded searches
180-
if query_opts.granule_list is None and query_opts.product_list is None:
180+
if (
181+
query_opts.granule_list is None
182+
and query_opts.product_list is None
183+
and output not in ['python', 'count']
184+
and not is_baseline
185+
):
181186
if query_opts.maxResults is None:
182-
query_opts.maxResults = asf.search_count(opts=query_opts)
187+
maxResults = asf.search_count(opts=query_opts)
188+
if maxResults > 2000:
189+
raise ValueError(
190+
(
191+
'SearchAPI no longer supports unbounded searches with expected results over 2000, '
192+
'please use the asf-search python module for long-lived searches or set `maxResults` to 2000 or less. '
193+
'To have SearchAPI automatically generate a python script for the equivalent search to your SearchAPI query '
194+
'set `output=python`'
195+
)
196+
)
183197
elif query_opts.maxResults <= 0:
184-
raise ValueError(f'Search keyword "maxResults" must be greater than 0')
185-
186-
query_opts.maxResults = min(1500, query_opts.maxResults)
198+
raise ValueError('Search keyword "maxResults" must be greater than 0')
187199

188200
searchOpts = SearchOptsModel(opts=query_opts, output=output, merged_args=merged_args, request_method=request.method)
189201
except (ValueError, ValidationError) as exc:
@@ -194,7 +206,7 @@ async def process_search_request(request: Request) -> SearchOptsModel:
194206

195207
async def process_baseline_request(request: Request) -> BaselineSearchOptsModel:
196208
"""Processes request to baseline endpoint"""
197-
searchOpts = await process_search_request(request=request)
209+
searchOpts = await process_search_request(request=request, is_baseline=True)
198210
reference = searchOpts.merged_args.get('reference')
199211
try:
200212
baselineSearchOpts = BaselineSearchOptsModel(**searchOpts.model_dump(), reference=reference)

0 commit comments

Comments
 (0)