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

disallow DOS set_queued in remote mode #5510

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

swheaton
Copy link
Contributor

@swheaton swheaton commented Feb 22, 2025

What changes are proposed in this pull request?

disallow DOS set_queued in remote mode

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

added unit test
tested manually in Teams context

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling for remote operations by preventing attempts to queue operations in unauthorized remote contexts. This update provides clearer feedback when such state changes are attempted.

Copy link
Contributor

coderabbitai bot commented Feb 22, 2025

Walkthrough

This pull request adds a conditional check in the update_run_state method of the MongoDelegatedOperationRepo class. When the run_state is set to ExecutionRunState.QUEUED, the method now verifies if the instance is in a remote context by checking its is_remote attribute. If true, a PermissionError is raised. Alongside this change, a new test is introduced to verify this behavior and existing tests have been updated to assert that the is_remote property is set correctly.

Changes

File Change Summary
fiftyone/factory/repos/delegated_operation.py Modified update_run_state to include a conditional check that raises a PermissionError when setting ExecutionRunState.QUEUED in a remote context.
tests/unittests/operators/delegated_tests.py Added test_set_queue_remote_service to verify the error is raised for remote services and updated test_queue_op_remote_service to assert the is_remote property.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Repo as MongoDelegatedOperationRepo
    Client->>Repo: update_run_state(id, ExecutionRunState.QUEUED, ...)
    note right of Repo: Check if is_remote is True
    alt is_remote True
        Repo-->>Client: Raise PermissionError("Cannot set queued run_state in remote context.")
    else is_remote False
        Repo->>Repo: Proceed with run state update
        Repo-->>Client: Return success response
    end
Loading

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • tom-vx51

Poem

Oh, I’m a rabbit, hopping through code,
Checking updates on each new node.
A queued state in a remote land,
Forbidden by checks oh so grand.
With tests in place and errors in sight,
I celebrate changes deep into the night!
🐇✨ Happy coding!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

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: 0

🧹 Nitpick comments (1)
tests/unittests/operators/delegated_tests.py (1)

1364-1384: Consider adding test for state transition to queued in remote mode.

While the current tests are good, consider adding a test that verifies the permission check when transitioning from another state (like RUNNING or SCHEDULED) to QUEUED in remote mode.

Example test case:

def test_transition_to_queue_remote_service(
    self,
    mock_is_remote_service,
    mock_get_operator,
    mock_operator_exists,
):
    mock_is_remote_service.return_value = True
    db = delegated_operation.MongoDelegatedOperationRepo()
    dos = DelegatedOperationService(repo=db)

    # Create and schedule an operation
    ctx = ExecutionContext()
    ctx.request_params = {"foo": "bar"}
    doc = dos.queue_operation(
        operator="@voxelfiftyone/operator/foo",
        label=mock_get_operator.return_value.name,
        delegation_target="test_target",
        context=ctx.serialize(),
    )
    self.docs_to_delete.append(doc)
    
    # Set it to running
    doc = dos.set_running(doc.id)
    self.assertEqual(doc.run_state, ExecutionRunState.RUNNING)
    
    # Attempt to transition to queued
    self.assertRaises(PermissionError, dos.set_queued, doc.id)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad05c8d and 3229699.

📒 Files selected for processing (2)
  • fiftyone/factory/repos/delegated_operation.py (1 hunks)
  • tests/unittests/operators/delegated_tests.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-app
  • GitHub Check: build / build
  • GitHub Check: e2e / test-e2e
  • GitHub Check: lint / eslint
  • GitHub Check: build
🔇 Additional comments (3)
fiftyone/factory/repos/delegated_operation.py (1)

334-337: LGTM! The permission check is well-placed and clear.

The added check prevents setting queued state in remote context, which aligns with the PR objective. The error message is descriptive and helpful.

tests/unittests/operators/delegated_tests.py (2)

347-347: LGTM! Good test setup validation and readability improvements.

The added assertion verifies remote mode setup, and the visual separators enhance code readability.

Also applies to: 1352-1353, 1359-1360


1364-1384: LGTM! Comprehensive test coverage for the new permission check.

The new test method effectively verifies that a PermissionError is raised when attempting to set queued state in remote mode. The test setup is clear and follows established patterns.

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.

1 participant