From 1442155cac91c392327770c2a3a1dd07208f6e10 Mon Sep 17 00:00:00 2001 From: SpicyGarlicAlbacoreRoll Date: Thu, 23 Oct 2025 10:53:59 -0800 Subject: [PATCH 1/2] fix: add check for ARIA stack size and http exception --- src/SearchAPI/application/application.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/SearchAPI/application/application.py b/src/SearchAPI/application/application.py index 825924d..839a5c2 100644 --- a/src/SearchAPI/application/application.py +++ b/src/SearchAPI/application/application.py @@ -270,6 +270,28 @@ def validate_wkt(wkt: str): 'repairs': repairs } +def _get_aria_baseline_stack(reference: str, opts: asf.ASFSearchOptions, output: str): + try: + if output.lower() == 'count': + stack_opts = asf.Products.ARIAS1GUNWProduct.get_stack_opts_for_frame(int(reference), opts=opts) + count=asf.search_count(opts=stack_opts) + if count < 2: + raise ValueError(f"Invalid stack frame, not enough scenes found with stack parameters. Stack size: {count}") + return Response( + content=str(count), + status_code=200, + media_type='text/html; charset=utf-8', + headers=constants.DEFAULT_HEADERS + ) + + stack = asf.stack_from_id(reference, opts=opts) + if len(stack) < 2: + raise ValueError(f"Invalid stack frame, not enough scenes found with stack parameters. Stack size: {len(stack)}") + response_info = as_output(stack, output) + return Response(**response_info) + except (KeyError, IndexError, ValueError) as exc: + raise HTTPException(detail=f"Ran into an issue building stack for frame: {reference}\nException: {str(exc)}", status_code=400) from exc + @router.get('/', response_class=JSONResponse) @router.get('/health', response_class=JSONResponse) From 9479336f20961512e34f6849ea9b989751f021a8 Mon Sep 17 00:00:00 2001 From: SpicyGarlicAlbacoreRoll Date: Thu, 23 Oct 2025 11:02:31 -0800 Subject: [PATCH 2/2] style: remove error when stack size less than 2, should be handled by client --- src/SearchAPI/application/application.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/SearchAPI/application/application.py b/src/SearchAPI/application/application.py index f0a1a97..8116389 100644 --- a/src/SearchAPI/application/application.py +++ b/src/SearchAPI/application/application.py @@ -268,22 +268,17 @@ def validate_wkt(wkt: str): } def _get_aria_baseline_stack(reference: str, opts: asf.ASFSearchOptions, output: str): + if output.lower() == 'count': + stack_opts = asf.Products.ARIAS1GUNWProduct.get_stack_opts_for_frame(int(reference), opts=opts) + count=asf.search_count(opts=stack_opts) + return Response( + content=str(count), + status_code=200, + media_type='text/html; charset=utf-8', + headers=constants.DEFAULT_HEADERS + ) try: - if output.lower() == 'count': - stack_opts = asf.Products.ARIAS1GUNWProduct.get_stack_opts_for_frame(int(reference), opts=opts) - count=asf.search_count(opts=stack_opts) - if count < 2: - raise ValueError(f"Invalid stack frame, not enough scenes found with stack parameters. Stack size: {count}") - return Response( - content=str(count), - status_code=200, - media_type='text/html; charset=utf-8', - headers=constants.DEFAULT_HEADERS - ) - stack = asf.stack_from_id(reference, opts=opts) - if len(stack) < 2: - raise ValueError(f"Invalid stack frame, not enough scenes found with stack parameters. Stack size: {len(stack)}") response_info = as_output(stack, output) return Response(**response_info) except (KeyError, IndexError, ValueError) as exc: