From 632f1404fdf8b4dffccdcb5d79b7ed40bdad228a Mon Sep 17 00:00:00 2001 From: Stuart Wheaton Date: Fri, 22 Nov 2024 15:27:07 -0500 Subject: [PATCH 1/3] fix foo.execute_operator() with delegation --- fiftyone/operators/delegated.py | 9 +++++---- fiftyone/operators/executor.py | 32 +++++++++++++------------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/fiftyone/operators/delegated.py b/fiftyone/operators/delegated.py index d4ef748473..314059f368 100644 --- a/fiftyone/operators/delegated.py +++ b/fiftyone/operators/delegated.py @@ -514,11 +514,12 @@ async def _execute_operator(self, doc): result = await do_execute_operator(operator, ctx, exhaust=True) outputs_schema = None - request_params = {**context.request_params, "results": result} try: - outputs = await resolve_type_with_context( - request_params, "outputs" - ) + # Resolve output types now + ctx.request_params["target"] = "outputs" + ctx.request_params["results"] = result + + outputs = resolve_type_with_context(operator, ctx) if outputs is not None: outputs_schema = outputs.to_json() except (AttributeError, Exception): diff --git a/fiftyone/operators/executor.py b/fiftyone/operators/executor.py index c15bbcc069..57846363f5 100644 --- a/fiftyone/operators/executor.py +++ b/fiftyone/operators/executor.py @@ -378,31 +378,25 @@ async def resolve_type(registry, operator_uri, request_params): required_secrets=operator._plugin_secrets, ) await ctx.resolve_secret_values(operator._plugin_secrets) - try: - return operator.resolve_type( - ctx, request_params.get("target", "inputs") - ) - except Exception as e: - return ExecutionResult(error=traceback.format_exc()) + return resolve_type_with_context(operator, ctx) -async def resolve_type_with_context(request_params, target=None): - """Resolves the "inputs" or "outputs" schema of an operator with the given - context. +def resolve_type_with_context(operator, context): + """Resolves the "inputs" or "outputs" schema of an operator with the given context. Args: - request_params: a dictionary of request parameters - target (None): the target schema ("inputs" or "outputs") - + operator: the :class:`fiftyone.operators.Operator` + context: the :class:`ExecutionContext` of an operator Returns: - the schema of "inputs" or "outputs" - :class:`fiftyone.operators.types.Property` of an operator, or None + the schema of "inputs" or "outputs" :class:`fiftyone.operators.types.Property` of + an operator, or None """ - computed_target = target or request_params.get("target", None) - computed_request_params = {**request_params, "target": computed_target} - operator_uri = request_params.get("operator_uri", None) - registry = OperatorRegistry() - return await resolve_type(registry, operator_uri, computed_request_params) + try: + return operator.resolve_type( + context, context.request_params.get("target", "inputs") + ) + except Exception as e: + return ExecutionResult(error=traceback.format_exc()) async def resolve_execution_options(registry, operator_uri, request_params): From d621680028cb5f083dbc9729251d5612277219fd Mon Sep 17 00:00:00 2001 From: Stuart Wheaton Date: Fri, 22 Nov 2024 15:30:38 -0500 Subject: [PATCH 2/3] keep it async to match before --- fiftyone/operators/delegated.py | 2 +- fiftyone/operators/executor.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fiftyone/operators/delegated.py b/fiftyone/operators/delegated.py index 314059f368..b27056c377 100644 --- a/fiftyone/operators/delegated.py +++ b/fiftyone/operators/delegated.py @@ -519,7 +519,7 @@ async def _execute_operator(self, doc): ctx.request_params["target"] = "outputs" ctx.request_params["results"] = result - outputs = resolve_type_with_context(operator, ctx) + outputs = await resolve_type_with_context(operator, ctx) if outputs is not None: outputs_schema = outputs.to_json() except (AttributeError, Exception): diff --git a/fiftyone/operators/executor.py b/fiftyone/operators/executor.py index 57846363f5..a797cf0ebd 100644 --- a/fiftyone/operators/executor.py +++ b/fiftyone/operators/executor.py @@ -379,10 +379,10 @@ async def resolve_type(registry, operator_uri, request_params): ) await ctx.resolve_secret_values(operator._plugin_secrets) - return resolve_type_with_context(operator, ctx) + return await resolve_type_with_context(operator, ctx) -def resolve_type_with_context(operator, context): +async def resolve_type_with_context(operator, context): """Resolves the "inputs" or "outputs" schema of an operator with the given context. Args: operator: the :class:`fiftyone.operators.Operator` From be38d26e4c0f4845d0bd26e15e5d884739d5a33b Mon Sep 17 00:00:00 2001 From: brimoor Date: Fri, 22 Nov 2024 17:11:51 -0500 Subject: [PATCH 3/3] lint --- fiftyone/operators/delegated.py | 1 - fiftyone/operators/executor.py | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fiftyone/operators/delegated.py b/fiftyone/operators/delegated.py index b27056c377..c03762348a 100644 --- a/fiftyone/operators/delegated.py +++ b/fiftyone/operators/delegated.py @@ -54,7 +54,6 @@ def queue_operation( - inputs_schema: the schema of the operator's inputs - outputs_schema: the schema of the operator's outputs - Returns: a :class:`fiftyone.factory.repos.DelegatedOperationDocument` """ diff --git a/fiftyone/operators/executor.py b/fiftyone/operators/executor.py index a797cf0ebd..fad1118dd1 100644 --- a/fiftyone/operators/executor.py +++ b/fiftyone/operators/executor.py @@ -383,13 +383,16 @@ async def resolve_type(registry, operator_uri, request_params): async def resolve_type_with_context(operator, context): - """Resolves the "inputs" or "outputs" schema of an operator with the given context. + """Resolves the "inputs" or "outputs" schema of an operator with the given + context. + Args: operator: the :class:`fiftyone.operators.Operator` context: the :class:`ExecutionContext` of an operator + Returns: - the schema of "inputs" or "outputs" :class:`fiftyone.operators.types.Property` of - an operator, or None + the "inputs" or "outputs" schema + :class:`fiftyone.operators.types.Property` of an operator, or None """ try: return operator.resolve_type(