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

store delegated operation IO in metadata #4436

Merged
merged 1 commit into from
Jun 7, 2024
Merged

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented May 28, 2024

What changes are proposed in this pull request?

Store delegated operation IO schema in metadata

How is this patch tested? If it is not, please explain why.

Unit and manual testins

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Enhanced metadata handling in delegated operations, including input and output schemas.
  • Bug Fixes

    • Improved accuracy in setting and extracting metadata during operation execution.
  • Tests

    • Added new unit tests to validate metadata handling and schema extraction in delegated operations.
  • Refactor

    • Streamlined code to include metadata parameters in various methods for better operation context management.
  • Chores

    • Removed unused ExecutionContext import to clean up the codebase.

Copy link
Contributor

coderabbitai bot commented May 28, 2024

Walkthrough

The recent changes introduce enhanced metadata handling and schema management for delegated operations in the FiftyOne codebase. Key updates include adding metadata parameters to various functions, setting and extracting schemas, and modifying unit tests to validate these features. This improves the flexibility and accuracy of operations by allowing detailed schema definitions and metadata to be passed and utilized throughout the execution process.

Changes

Files/Modules Change Summary
fiftyone/factory/repos/delegated_operation.py Added outputs_schema parameter to update_run_state and set metadata in queue_operation if provided.
fiftyone/factory/repos/delegated_operation_doc.py Added metadata attribute to DelegatedOperationDoc class, initialized in __init__ and set during object creation from MongoDB document.
fiftyone/operators/delegated.py Added metadata parameter to queue_operation method and included logic to handle output schema in set_completed method.
fiftyone/operators/executor.py Modified execute_or_delegate_operator to handle input schemas and return inputs. Added resolve_type_with_context function for schema resolution.
fiftyone/operators/server.py Removed ExecutionContext from the list of imported entities.
tests/unittests/delegated_operators_tests.py Added MockInputs and MockOutputs classes, modified MockOperator class, and included assertions for metadata in test methods.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant FiftyOneSystem
    participant DelegatedOperationQueue
    participant Database

    User->>FiftyOneSystem: Initiate Operation
    FiftyOneSystem->>DelegatedOperationQueue: queue_operation(metadata)
    DelegatedOperationQueue->>Database: Store Operation with Metadata
    Database-->>DelegatedOperationQueue: Acknowledge Storage
    DelegatedOperationQueue->>FiftyOneSystem: Operation Queued

    FiftyOneSystem->>DelegatedOperationQueue: set_completed(outputs_schema)
    DelegatedOperationQueue->>Database: Update Operation with Output Schema
    Database-->>DelegatedOperationQueue: Acknowledge Update
    DelegatedOperationQueue->>FiftyOneSystem: Operation Completed
    FiftyOneSystem->>User: Notify Completion
Loading

Poem

In the code where schemas dance,
Metadata now gets its chance.
Inputs, outputs, all aligned,
In operations, clearly defined.
With tests to guide and docs to show,
Our system's smarter, watch it grow!
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@imanjra imanjra force-pushed the bugfix/run-io-schema branch from b278aef to 171035f Compare May 29, 2024 03:50
@imanjra imanjra marked this pull request as ready for review May 29, 2024 03:51
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between f2720c8 and 171035f.
Files selected for processing (5)
  • fiftyone/factory/repos/delegated_operation.py (5 hunks)
  • fiftyone/factory/repos/delegated_operation_doc.py (3 hunks)
  • fiftyone/operators/delegated.py (7 hunks)
  • fiftyone/operators/executor.py (4 hunks)
  • tests/unittests/delegated_operators_tests.py (8 hunks)
Additional comments not posted (15)
fiftyone/factory/repos/delegated_operation_doc.py (2)

52-52: Initialization of metadata attribute to None.

This change aligns with the PR's objective to enhance metadata handling by initializing the metadata attribute in the DelegatedOperationDocument class.


107-107: Conditional assignment of metadata from the document.

This ensures that the metadata attribute is set based on the presence of the "metadata" key in the input dictionary, which is crucial for the dynamic handling of metadata in operations.

fiftyone/operators/delegated.py (3)

20-20: Import of resolve_type_with_context.

This import is necessary for the new functionality in the set_completed method where the output schema is resolved.


Line range hint 42-56: Addition of metadata parameter in queue_operation.

The inclusion of a metadata parameter allows passing optional metadata containing input and output schemas, which is essential for the new metadata handling features.


128-145: Handling of output schema resolution in set_completed.

This change is crucial for storing the output schema when marking an operation as completed, enhancing the robustness of metadata management.

fiftyone/factory/repos/delegated_operation.py (3)

47-47: Addition of outputs_schema parameter in update_run_state.

This addition supports the new functionality of updating the operation's run state with an output schema, aligning with the PR's objectives related to schema management.


168-172: Handling of metadata in queue_operation.

This ensures that metadata can be optionally included when queuing operations, which is vital for the enhanced metadata handling capabilities introduced in this PR.


Line range hint 231-254: Enhanced handling of outputs_schema in update_run_state.

This modification allows the dynamic updating of the metadata.outputs_schema based on the operation's completion state, which is a significant enhancement for schema management.

fiftyone/operators/executor.py (2)

222-222: Ensure proper unpacking of prepared in execute_or_delegate_operator.

The unpacking of the prepared tuple to include inputs aligns with the changes in the prepare_operator_executor function, ensuring that input schemas are correctly handled.


379-395: Review the new function resolve_type_with_context.

This function adds flexibility in resolving either the inputs or outputs schema based on the provided context and target. It's a useful addition for dynamic schema resolution based on operation context.

tests/unittests/delegated_operators_tests.py (5)

47-50: Ensure the to_json method in MockInputs class correctly represents the expected schema.


52-55: Ensure the to_json method in MockOutputs class correctly represents the expected schema.


187-187: The assertion self.assertIsNone(doc.metadata) is correct as per the initial state of metadata being None.


189-203: The test correctly handles the scenario where metadata is provided and asserts its presence and correctness.


Line range hint 297-334: The test test_set_run_states effectively checks the metadata handling during different states of operation execution. Ensure that the metadata includes both inputs_schema and outputs_schema correctly.

@imanjra imanjra force-pushed the bugfix/run-io-schema branch from 171035f to 0d95304 Compare May 29, 2024 04:07
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range and nitpick comments (10)
fiftyone/operators/delegated.py (2)

42-42: Ensure proper documentation for the metadata parameter in the queue_operation method.

The addition of the metadata parameter is well-integrated, but consider enhancing the docstring to include possible keys and value types within the metadata dictionary for better clarity.


410-410: Clarify the unpacking of variables in _execute_operator.

The unpacking of variables in this method is unclear, especially with placeholders like _ and __. Consider using more descriptive variable names to improve code readability.

fiftyone/factory/repos/delegated_operation.py (2)

47-47: Ensure the outputs_schema parameter is documented in the update_run_state method.

The addition of the outputs_schema parameter is crucial for schema management. Enhance the method's docstring to describe this parameter's role and expected data type.


Line range hint 231-254: Refactor to improve error handling in update_run_state.

The method uses a bare except which is generally discouraged. Specify the exceptions you expect to handle to avoid catching unexpected exceptions.

- except:
+ except SpecificExceptionType:

Additionally, enhance the logging to provide more context about the error.

fiftyone/operators/executor.py (4)

Line range hint 281-281: Avoid using bare except statements.

Using bare except can catch unexpected exceptions and obscure programming errors. Specify the exception types to handle them appropriately.

- except:
+ except Exception as e:
    return ExecutionResult(executor=executor, error=traceback.format_exc())

Line range hint 288-288: Avoid using bare except statements.

Similar to the previous comment, specify the exception types to improve error handling.

- except:
+ except Exception as e:
    return ExecutionResult(executor=executor, error=traceback.format_exc())

Line range hint 420-420: Unused local variable e.

The variable e is declared but not used. Consider removing it or using it appropriately.

- except Exception as e:
+ except Exception:
    return ExecutionResult(error=traceback.format_exc())

Line range hint 914-914: Avoid inequality comparisons to True.

Use if not error.custom: for false checks to improve readability and Pythonic style.

- if not error.custom != True:
+ if not error.custom:
tests/unittests/delegated_operators_tests.py (2)

Line range hint 652-652: Avoid using bare except statements as they can catch unexpected exceptions and hide programming errors.

- except:
+ except Exception as e:
+     # Handle specific exception or log it
+     print(f"Error occurred: {e}")

Line range hint 694-694: Avoid using bare except statements as they can obscure the source of errors.

- except:
+ except Exception as e:
+     # Handle specific exception or log it
+     print(f"Error occurred: {e}")
Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 171035f and 0d95304.
Files selected for processing (5)
  • fiftyone/factory/repos/delegated_operation.py (5 hunks)
  • fiftyone/factory/repos/delegated_operation_doc.py (3 hunks)
  • fiftyone/operators/delegated.py (7 hunks)
  • fiftyone/operators/executor.py (4 hunks)
  • tests/unittests/delegated_operators_tests.py (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • fiftyone/factory/repos/delegated_operation_doc.py
Additional Context Used
Ruff (30)
fiftyone/factory/repos/delegated_operation.py (1)

187-187: Do not use bare except

fiftyone/operators/delegated.py (2)

133-133: Do not use bare except


380-380: Do not use bare except

fiftyone/operators/executor.py (6)

160-160: Do not use bare except


281-281: Do not use bare except


288-288: Do not use bare except


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


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


914-914: Avoid inequality comparisons to True; use if not error.custom: for false checks

tests/unittests/delegated_operators_tests.py (21)

309-309: f-string without any placeholders


363-363: f-string without any placeholders


391-391: f-string without any placeholders


425-425: f-string without any placeholders


459-459: f-string without any placeholders


485-485: f-string without any placeholders


526-526: f-string without any placeholders


563-563: f-string without any placeholders


613-613: f-string without any placeholders


652-652: Do not use bare except


678-678: f-string without any placeholders


694-694: Do not use bare except


789-789: f-string without any placeholders


797-797: f-string without any placeholders


805-805: f-string without any placeholders


813-813: f-string without any placeholders


860-860: f-string without any placeholders


982-982: f-string without any placeholders


995-995: f-string without any placeholders


1071-1071: f-string without any placeholders


1091-1091: f-string without any placeholders

Additional comments not posted (8)
fiftyone/operators/delegated.py (1)

66-66: Validate the structure of metadata before using it.

Consider adding validation for the metadata parameter to ensure it contains the expected structure and data types before proceeding with the operation queuing.

fiftyone/factory/repos/delegated_operation.py (1)

168-172: Validate the metadata parameter in the queue_operation method.

Consider implementing validation for the metadata parameter to ensure it adheres to the expected structure and data types. This can prevent potential issues during operation execution.

fiftyone/operators/executor.py (1)

222-222: Ensure proper unpacking of prepared with added inputs.

This change aligns with the PR's objective to enhance metadata handling by including input schemas.

tests/unittests/delegated_operators_tests.py (5)

47-50: The MockInputs class correctly implements the to_json method.


52-54: The MockOutputs class correctly implements the to_json method.


87-91: The MockOperatorWithIO class correctly implements the resolve_input and resolve_output methods to return instances of MockInputs and MockOutputs, respectively.


192-192: The queue_operation method in DelegatedOperationServiceTests correctly handles metadata, ensuring it is set and retrieved as expected. This aligns with the PR's objective to enhance metadata handling.

Also applies to: 194-208


Line range hint 302-340: The test test_set_run_states effectively verifies the metadata handling by setting and checking inputs_schema and outputs_schema. This is crucial for ensuring the integrity of the metadata functionality.

@@ -366,6 +376,24 @@ async def resolve_type(registry, operator_uri, request_params):
return ExecutionResult(error=traceback.format_exc())


def resolve_type_with_context(context, target: str = None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused local variable e.

The variable e is declared but not used. Consider removing it if it's unnecessary, or use it appropriately if needed.

- except Exception as e:
+ except Exception:
    return ExecutionResult(error=traceback.format_exc())

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
def resolve_type_with_context(context, target: str = None):
def resolve_type_with_context(context, target: str = None):
try:
# Some code that might raise an exception
pass
except Exception:
return ExecutionResult(error=traceback.format_exc())

Comment on lines 128 to 147
outputs_schema = None
try:
doc = self._repo.get(_id=doc_id)
outputs = resolve_type_with_context(doc.context, "outputs")
outputs_schema = outputs.to_json()
except:
logger.warning(
"Failed to resolve output schema for the operation."
+ traceback.format_exc(),
)

return self._repo.update_run_state(
_id=doc_id,
run_state=ExecutionRunState.COMPLETED,
result=result,
progress=progress,
run_link=run_link,
outputs_schema=outputs_schema,
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to improve error handling and logging in set_completed.

The current implementation uses a bare except which is generally discouraged as it can catch unexpected exceptions. Consider specifying the exceptions you expect to handle.

- except:
+ except SpecificExceptionType:

Also, enhance the logging to include more context about the error.

Committable suggestion was skipped due low confidence.

@imanjra imanjra requested a review from a team May 29, 2024 15:19
@imanjra imanjra force-pushed the bugfix/run-io-schema branch from 0d95304 to 37f5f2b Compare May 29, 2024 19:18
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range and nitpick comments (9)
fiftyone/operators/delegated.py (2)

Line range hint 42-56: Add detailed documentation for the metadata parameter.

The metadata parameter in the queue_operation method could benefit from more detailed documentation, especially explaining what inputs_schema and outputs_schema are expected to contain and how they are used.


Line range hint 380-380: Avoid using bare except in execute_operation.

Using a bare except can catch unexpected exceptions and obscure the source of errors. Specify the exceptions that are expected to be handled.

- except:
+ except ExpectedExceptionType:
fiftyone/factory/repos/delegated_operation.py (2)

47-47: Ensure outputs_schema is documented in the update_run_state method.

The outputs_schema parameter is added to the update_run_state method but lacks documentation. It's important to describe its purpose, expected content, and how it interacts with other parameters or affects the method's behavior.


Line range hint 187-187: Handle potential exceptions more gracefully in queue_operation.

The method uses a bare except which might suppress important errors and make debugging difficult. It's advisable to catch specific exceptions or at least log the error appropriately.

- except:
+ except Exception as e:
+     logger.error("Failed to resolve dataset_id: %s", str(e))
fiftyone/operators/executor.py (4)

Line range hint 281-281: Avoid using bare except statements.

Using bare except statements can catch unexpected exceptions and obscure underlying bugs. Specify the exception type to improve error handling.

- except:
+ except Exception as e:
    return ExecutionResult(executor=executor, error=traceback.format_exc())

Line range hint 288-288: Avoid using bare except statements.

Similar to the previous comment, specify the exception type to catch specific errors and improve the clarity and maintainability of the code.

- except:
+ except Exception as e:
    return ExecutionResult(executor=executor, error=traceback.format_exc())

Line range hint 420-420: Unused local variable e.

The variable e is declared but not used in the resolve_execution_options function. It's good practice to either use the variable or not include it in the exception clause.

- except Exception as e:
+ except Exception:
    return ExecutionResult(error=traceback.format_exc())

Line range hint 914-914: Avoid inequality comparisons to True.

For clarity and consistency, use if not error.custom: instead of checking inequality to True.

- if not error.custom != True:
+ if not error.custom:
tests/unittests/delegated_operators_tests.py (1)

Line range hint 652-652: Using bare except statements can lead to masking unexpected errors and make debugging more difficult. It's recommended to catch specific exceptions.

- except:
+ except ExpectedException:
    # handle specific exception

Also applies to: 694-694

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0d95304 and 37f5f2b.
Files selected for processing (5)
  • fiftyone/factory/repos/delegated_operation.py (6 hunks)
  • fiftyone/factory/repos/delegated_operation_doc.py (3 hunks)
  • fiftyone/operators/delegated.py (7 hunks)
  • fiftyone/operators/executor.py (4 hunks)
  • tests/unittests/delegated_operators_tests.py (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • fiftyone/factory/repos/delegated_operation_doc.py
Additional Context Used
Ruff (30)
fiftyone/factory/repos/delegated_operation.py (1)

187-187: Do not use bare except

fiftyone/operators/delegated.py (2)

133-133: Do not use bare except


380-380: Do not use bare except

fiftyone/operators/executor.py (6)

160-160: Do not use bare except


281-281: Do not use bare except


288-288: Do not use bare except


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


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


914-914: Avoid inequality comparisons to True; use if not error.custom: for false checks

tests/unittests/delegated_operators_tests.py (21)

309-309: f-string without any placeholders


363-363: f-string without any placeholders


391-391: f-string without any placeholders


425-425: f-string without any placeholders


459-459: f-string without any placeholders


485-485: f-string without any placeholders


526-526: f-string without any placeholders


563-563: f-string without any placeholders


613-613: f-string without any placeholders


652-652: Do not use bare except


678-678: f-string without any placeholders


694-694: Do not use bare except


789-789: f-string without any placeholders


797-797: f-string without any placeholders


805-805: f-string without any placeholders


813-813: f-string without any placeholders


860-860: f-string without any placeholders


982-982: f-string without any placeholders


995-995: f-string without any placeholders


1071-1071: f-string without any placeholders


1091-1091: f-string without any placeholders

Additional comments not posted (7)
fiftyone/operators/executor.py (2)

222-222: Ensure unpacking of prepared matches expected structure.

The unpacking of the prepared tuple now includes inputs, which aligns with the changes made to the prepare_operator_executor function to return these additional parameters. This is a necessary change to handle the new metadata requirements.


379-379: Unused local variable e.

The variable e is declared but not used. Consider removing it if it's unnecessary, or use it appropriately if needed.

- except Exception as e:
+ except Exception:
    return ExecutionResult(error=traceback.format_exc())

Likely invalid or redundant comment.

tests/unittests/delegated_operators_tests.py (5)

47-50: The to_json method in MockInputs class correctly returns a JSON representation of inputs. This is consistent with the changes described in the PR.


52-55: The to_json method in MockOutputs class correctly returns a JSON representation of outputs. This is consistent with the changes described in the PR.


87-91: The resolve_input and resolve_output methods in MockOperatorWithIO class correctly return instances of MockInputs and MockOutputs, respectively. This aligns with the changes described in the PR and addresses previous review comments.


192-192: The metadata handling in test_delegate_operation method is correctly implemented. The test verifies that metadata is None when not provided and correctly matches the provided metadata when it is supplied.

Also applies to: 207-208


Line range hint 302-340: The test_set_run_states method correctly tests the metadata handling for inputs_schema and outputs_schema. The assertions verify that the metadata is stored and retrieved as expected, which is crucial for the functionality introduced in this PR.

Comment on lines 128 to 139
outputs_schema = None
try:
doc = self._repo.get(_id=doc_id)
outputs = resolve_type_with_context(doc.context, "outputs")
outputs_schema = outputs.to_json()
except:
logger.warning(
"Failed to resolve output schema for the operation."
+ traceback.format_exc(),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to improve error handling and logging in set_completed.

The current implementation uses a bare except which is generally discouraged as it can catch unexpected exceptions. Consider specifying the exceptions you expect to handle.

- except:
+ except SpecificExceptionType:

Also, enhance the logging to include more context about the error.

Committable suggestion was skipped due low confidence.

mock_load_dataset.return_value = MockDataset()
mock_get_operator.return_value = MockOperatorWithIO()
doc = self.svc.queue_operation(
operator="@voxelfiftyone/operator/foo",
label=mock_get_operator.return_value.name,
delegation_target=f"test_target",
Copy link
Contributor

Choose a reason for hiding this comment

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

Several f-strings in the test methods do not contain placeholders, which suggests they are unnecessary. Consider removing the f-string prefix if no variables are being interpolated.

- f"test_dataset_{dataset_id}"
+ "test_dataset_{dataset_id}"

Also applies to: 363-363, 391-391, 425-425, 459-459, 485-485, 526-526, 563-563, 613-613, 678-678, 789-789, 797-797, 805-805, 813-813, 860-860, 982-982, 995-995, 1071-1071, 1091-1091

Committable suggestion was skipped due low confidence.

Comment on lines +255 to +263
metadata = {"inputs_schema": None, "outputs_schema": None}

try:
metadata["inputs_schema"] = inputs.to_json()
except Exception as e:
logger.warning(
f"Failed to resolve inputs schema for the operation: {str(e)}"
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Handle potential exceptions when converting inputs to JSON.

Consider initializing metadata with default values or ensuring it's always defined before use to avoid potential KeyError issues. Also, ensure that the metadata handling logic is robust against exceptions when converting inputs to JSON.

- metadata = {"inputs_schema": None, "outputs_schema": None}
+ metadata = {"inputs_schema": None, "outputs_schema": None}  # Default value to ensure key existence

try:
    metadata["inputs_schema"] = inputs.to_json()
except Exception as e:
    logger.warning(f"Failed to resolve inputs schema for the operation: {str(e)}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
metadata = {"inputs_schema": None, "outputs_schema": None}
try:
metadata["inputs_schema"] = inputs.to_json()
except Exception as e:
logger.warning(
f"Failed to resolve inputs schema for the operation: {str(e)}"
)
metadata = {"inputs_schema": None, "outputs_schema": None} # Default value to ensure key existence
try:
metadata["inputs_schema"] = inputs.to_json()
except Exception as e:
logger.warning(
f"Failed to resolve inputs schema for the operation: {str(e)}"
)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (4)
fiftyone/operators/executor.py (4)

Line range hint 281-281: Avoid using bare except statements.

- except:
+ except Exception as e:
    return ExecutionResult(executor=executor, error=traceback.format_exc())

Using a bare except can catch unexpected events like memory errors, interrupts, system exit, and so on. Always specify the exception type to prevent catching unintended exceptions.


Line range hint 288-288: Avoid using bare except statements.

- except:
+ except Exception as e:
    return ExecutionResult(executor=executor, error=traceback.format_exc())

Similar to the previous comment, specify the exception type to ensure that only expected errors are caught.


Line range hint 420-420: Unused local variable e.

- except Exception as e:
+ except Exception:
    return ExecutionResult(error=traceback.format_exc())

Again, the variable e is declared but not used. Removing it can clean up the code and avoid confusion.


Line range hint 914-914: Avoid inequality comparisons to True; use if not error.custom: for false checks.

- if not error.custom != True:
+ if not error.custom:

This change simplifies the condition and improves readability.

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 37f5f2b and 132309f.
Files selected for processing (1)
  • fiftyone/operators/executor.py (4 hunks)
Additional Context Used
Ruff (6)
fiftyone/operators/executor.py (6)

160-160: Do not use bare except


281-281: Do not use bare except


288-288: Do not use bare except


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


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


914-914: Avoid inequality comparisons to True; use if not error.custom: for false checks

Additional comments not posted (2)
fiftyone/operators/executor.py (2)

255-263: Handle potential exceptions when converting inputs to JSON.

- metadata = {"inputs_schema": None, "outputs_schema": None}
+ metadata = {"inputs_schema": None, "outputs_schema": None}  # Default value to ensure key existence

try:
    metadata["inputs_schema"] = inputs.to_json()
except Exception as e:
    logger.warning(f"Failed to resolve inputs schema for the operation: {str(e)}")

Ensure that metadata is always defined before use to avoid potential KeyError issues. Also, consider initializing metadata with default values.

Likely invalid or redundant comment.


379-379: Unused local variable e.

- except Exception as e:
+ except Exception:
    return ExecutionResult(error=traceback.format_exc())

The variable e is declared but not used. Consider removing it if it's unnecessary, or use it appropriately if needed.

Likely invalid or redundant comment.

@@ -219,7 +219,7 @@ async def execute_or_delegate_operator(
if isinstance(prepared, ExecutionResult):
raise prepared.to_exception()
else:
operator, executor, ctx = prepared
operator, executor, ctx, inputs = prepared
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper unpacking of prepared with clear variable names.

- operator, executor, ctx, inputs = prepared
+ operator, executor, ctx, inputs = prepared  # Ensure these variables are correctly mapped from `prepared`

Consider adding a comment or assertion to ensure that the unpacking aligns with the expected structure of prepared.

Committable suggestion was skipped due low confidence.

@benjaminpkane
Copy link
Contributor

Teams PR has conflicts. More info here 🙏

@imanjra
Copy link
Contributor Author

imanjra commented May 30, 2024

This will require a manual merge and conflict resolution. Any objection to ignoring Pull Request / teams (pull_request) stage for this PR?

@benjaminpkane
Copy link
Contributor

benjaminpkane commented May 30, 2024

This will require a manual merge and conflict resolution. Any objection to ignoring Pull Request / teams (pull_request) stage for this PR?

Sure, the check isn't required. But if a bugfix/run-io-schema branch in Teams is pushed with conflicts resolved it will pass if it is rerun

Trying to avoid things hitting develop that will have conflicts

@imanjra imanjra marked this pull request as draft May 31, 2024 03:15
@imanjra imanjra force-pushed the bugfix/run-io-schema branch from 132309f to d7421c0 Compare June 4, 2024 19:37
@imanjra imanjra marked this pull request as ready for review June 4, 2024 19:38
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (6)
fiftyone/factory/repos/delegated_operation.py (1)

Line range hint 187-187: Avoid using bare except as it can catch unexpected exceptions. Specify the exceptions you expect to handle.

- except:
+ except SpecificExceptionType:

Also, enhance the logging to include more context about the error.

fiftyone/operators/executor.py (5)

Line range hint 281-281: Avoid using bare except statements.

- except:
+ except Exception as e:
    return ExecutionResult(executor=executor, error=traceback.format_exc())

Line range hint 288-288: Avoid using bare except statements.

- except:
+ except Exception as e:
    return ExecutionResult(executor=executor, error=traceback.format_exc())

Line range hint 375-375: Unused local variable e.

- except Exception as e:
+ except Exception:
    return ExecutionResult(error=traceback.format_exc())

Line range hint 420-420: Unused local variable e.

- except Exception as e:
+ except Exception:
    return ExecutionResult(error=traceback.format_exc())

Line range hint 914-914: Avoid inequality comparisons to True; use if not error.custom: for false checks.

- if not error.custom != True:
+ if not error.custom:
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 132309f and d7421c0.

Files selected for processing (6)
  • fiftyone/factory/repos/delegated_operation.py (6 hunks)
  • fiftyone/factory/repos/delegated_operation_doc.py (3 hunks)
  • fiftyone/operators/delegated.py (7 hunks)
  • fiftyone/operators/executor.py (4 hunks)
  • fiftyone/operators/server.py (1 hunks)
  • tests/unittests/delegated_operators_tests.py (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • fiftyone/factory/repos/delegated_operation_doc.py
Additional context used
Ruff
fiftyone/operators/delegated.py

135-135: Do not use bare except (E722)


382-382: Do not use bare except (E722)

fiftyone/factory/repos/delegated_operation.py

187-187: Do not use bare except (E722)

fiftyone/operators/executor.py

160-160: Do not use bare except (E722)


281-281: Do not use bare except (E722)


288-288: Do not use bare except (E722)


375-375: Local variable e is assigned to but never used (F841)


420-420: Local variable e is assigned to but never used (F841)


914-914: Avoid inequality comparisons to True; use if not error.custom: for false checks (E712)

tests/unittests/delegated_operators_tests.py

309-309: f-string without any placeholders (F541)


363-363: f-string without any placeholders (F541)


391-391: f-string without any placeholders (F541)


425-425: f-string without any placeholders (F541)


459-459: f-string without any placeholders (F541)


485-485: f-string without any placeholders (F541)


526-526: f-string without any placeholders (F541)


563-563: f-string without any placeholders (F541)


613-613: f-string without any placeholders (F541)


652-652: Do not use bare except (E722)


678-678: f-string without any placeholders (F541)


694-694: Do not use bare except (E722)


789-789: f-string without any placeholders (F541)


797-797: f-string without any placeholders (F541)


805-805: f-string without any placeholders (F541)


813-813: f-string without any placeholders (F541)


860-860: f-string without any placeholders (F541)


982-982: f-string without any placeholders (F541)


995-995: f-string without any placeholders (F541)


1071-1071: f-string without any placeholders (F541)


1091-1091: f-string without any placeholders (F541)

Additional comments not posted (13)
fiftyone/operators/server.py (1)

Line range hint 1-1: No specific changes to review in this file. Ensure that changes in other files are consistent with the usage here.

fiftyone/operators/delegated.py (3)

Line range hint 42-56: The addition of metadata parameter in queue_operation method is consistent with the PR's objective to enhance metadata handling.


20-20: Ensure resolve_type_with_context is properly imported and used, as it's a new addition to the imports.

Verification successful

The function resolve_type_with_context is properly imported and used in the codebase.

  • Import: fiftyone/operators/delegated.py
  • Definition: fiftyone/operators/executor.py
  • Usage: fiftyone/operators/delegated.py
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `resolve_type_with_context` in the codebase.

# Test: Search for the function usage. Expect: Proper usage and import.
rg --type python $'resolve_type_with_context'

Length of output: 75



Script:

#!/bin/bash
# Description: Verify the usage of `resolve_type_with_context` in the codebase.

# Test: Search for the function usage. Expect: Proper usage and import.
rg --type py $'resolve_type_with_context'

Length of output: 298


147-147: Ensure that outputs_schema is correctly handled and integrated into the system, as it's a new addition.

Verification successful

Ensure that outputs_schema is correctly handled and integrated into the system, as it's a new addition.

  • tests/unittests/delegated_operators_tests.py: The test verifies that outputs_schema is correctly set in the metadata.
  • fiftyone/operators/executor.py: outputs_schema is initialized and potentially set within a try block.
  • fiftyone/operators/delegated.py: outputs_schema is documented, initialized, and set based on resolved outputs.
  • fiftyone/factory/repos/delegated_operation.py: outputs_schema is used in method parameters and conditionally updated in the metadata.

These occurrences indicate that outputs_schema is properly handled and integrated into the system.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the handling of `outputs_schema` in the codebase.

# Test: Search for the usage of `outputs_schema`. Expect: Proper handling and integration.
rg --type python $'outputs_schema'

Length of output: 64



Script:

#!/bin/bash
# Description: Verify the handling of `outputs_schema` in the codebase.

# Test: Search for the usage of `outputs_schema`. Expect: Proper handling and integration.
rg --type py 'outputs_schema'

Length of output: 990



Script:

#!/bin/bash
# Description: Extract lines around the occurrences of `outputs_schema` for detailed inspection.

# Extract lines from tests/unittests/delegated_operators_tests.py
rg --context 5 'outputs_schema' tests/unittests/delegated_operators_tests.py

# Extract lines from fiftyone/operators/executor.py
rg --context 5 'outputs_schema' fiftyone/operators/executor.py

# Extract lines from fiftyone/operators/delegated.py
rg --context 5 'outputs_schema' fiftyone/operators/delegated.py

# Extract lines from fiftyone/factory/repos/delegated_operation.py
rg --context 5 'outputs_schema' fiftyone/factory/repos/delegated_operation.py

Length of output: 3386

fiftyone/factory/repos/delegated_operation.py (1)

47-47: The addition of outputs_schema parameter in update_run_state method aligns with the PR's objective to enhance metadata handling.

fiftyone/operators/executor.py (3)

222-222: Ensure proper unpacking of prepared with clear variable names.


255-263: Handle potential exceptions when converting inputs to JSON.


379-395: Add a new function resolve_type_with_context to handle schema resolution.

tests/unittests/delegated_operators_tests.py (5)

47-55: LGTM! The new MockInputs and MockOutputs classes with to_json methods are well-implemented.


86-92: LGTM! The MockOperatorWithIO class correctly implements resolve_input and resolve_output methods to return instances of MockInputs and MockOutputs.


194-208: The handling of metadata in queue_operation is correctly implemented, ensuring that it is passed and stored as expected.


Line range hint 302-340: The tests for setting run states with metadata handling are well-implemented. The assertions correctly check the metadata values against expected schemas.

Tools
Ruff

309-309: f-string without any placeholders (F541)


192-192: Ensure metadata is handled correctly when not provided.

Verification successful

The search results show that doc.metadata is being checked for None and compared against expected values in the test cases. This indicates that the code is handling the absence of metadata correctly.

  • self.assertIsNone(doc.metadata) ensures that metadata can be None.
  • self.assertEqual(doc.metadata, {"inputs_schema": mock_inputs.to_json()}) and similar assertions ensure that metadata is correctly set and validated when provided.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the absence of metadata does not cause issues in other parts of the codebase.

# Test: Search for the function usage. Expect: Proper handling of `None` metadata.
rg --type python $'doc.metadata'

Length of output: 62



Script:

#!/bin/bash
# Description: Verify that the absence of metadata does not cause issues in other parts of the codebase.

# Test: Search for the function usage. Expect: Proper handling of `None` metadata.
rg --type py $'doc.metadata'

Length of output: 295



Script:

#!/bin/bash
# Description: Extract lines around occurrences of `doc.metadata` to verify proper handling of `None` metadata.

# Extract 5 lines before and after each occurrence of `doc.metadata` in the specified file.
rg --type py --context 5 $'doc.metadata' tests/unittests/delegated_operators_tests.py

Length of output: 1267

Comment on lines +128 to +139
outputs_schema = None
try:
doc = self._repo.get(_id=doc_id)
outputs = asyncio.run(
resolve_type_with_context(doc.context, "outputs")
)
outputs_schema = outputs.to_json()
except:
logger.warning(
"Failed to resolve output schema for the operation."
+ traceback.format_exc(),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using bare except as it can catch unexpected exceptions. Specify the exceptions you expect to handle.

- except:
+ except SpecificExceptionType:

Also, enhance the logging to include more context about the error.

Committable suggestion was skipped due to low confidence.

Tools
Ruff

135-135: Do not use bare except (E722)

Comment on lines +168 to +172
# also set the metadata (not required)
metadata = kwargs.get("metadata", None)
if metadata:
setattr(op, "metadata", metadata)

Copy link
Contributor

Choose a reason for hiding this comment

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

Handling of metadata in queue_operation method should ensure it does not overwrite existing metadata if present. Consider merging with existing metadata or explicitly handling cases where metadata might already exist.

+ if metadata:
+     existing_metadata = getattr(op, 'metadata', {})
+     merged_metadata = {**existing_metadata, **metadata}
+     setattr(op, 'metadata', merged_metadata)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
# also set the metadata (not required)
metadata = kwargs.get("metadata", None)
if metadata:
setattr(op, "metadata", metadata)
# also set the metadata (not required)
metadata = kwargs.get("metadata", None)
if metadata:
existing_metadata = getattr(op, 'metadata', {})
merged_metadata = {**existing_metadata, **metadata}
setattr(op, 'metadata', merged_metadata)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants