Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 19 additions & 7 deletions src/SearchAPI/application/asf_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down