Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix execute_operator() with delegation #5180

Merged
merged 3 commits into from
Nov 23, 2024
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
10 changes: 5 additions & 5 deletions fiftyone/operators/delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
"""
Expand Down Expand Up @@ -514,11 +513,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 = await resolve_type_with_context(operator, ctx)
if outputs is not None:
outputs_schema = outputs.to_json()
except (AttributeError, Exception):
Expand Down
27 changes: 12 additions & 15 deletions fiftyone/operators/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,31 +378,28 @@ 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 await resolve_type_with_context(operator, ctx)


async def resolve_type_with_context(request_params, target=None):
async 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"
the "inputs" or "outputs" schema
: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())
Comment on lines +397 to +402
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance error handling

The error handling could be improved in two ways:

  1. The caught exception 'e' is unused
  2. The error message from the exception is not included in the ExecutionResult

Consider this improvement:

     try:
         return operator.resolve_type(
             context, context.request_params.get("target", "inputs")
         )
-    except Exception as e:
-        return ExecutionResult(error=traceback.format_exc())
+    except Exception as e:
+        return ExecutionResult(
+            error=traceback.format_exc(),
+            error_message=str(e)
+        )

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Ruff (0.7.0)

401-401: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)



async def resolve_execution_options(registry, operator_uri, request_params):
Expand Down
Loading