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: more permissive deletes #333

Merged
merged 2 commits into from
Jun 20, 2024
Merged

fix: more permissive deletes #333

merged 2 commits into from
Jun 20, 2024

Conversation

jamescalam
Copy link
Member

@jamescalam jamescalam commented Jun 20, 2024

PR Type

Bug fix, Enhancement


Description

  • Modified the delete method in semantic_router/layer.py to handle non-existent routes more permissively by logging a warning instead of raising a ValueError and ensuring the index is updated.
  • Updated the project version in pyproject.toml from 0.0.47 to 0.0.48.

Changes walkthrough 📝

Relevant files
Bug fix
layer.py
Modify route deletion logic to be more permissive               

semantic_router/layer.py

  • Changed error handling for non-existent routes in the delete method.
  • Replaced ValueError with a warning log and an index delete operation.
  • +3/-3     
    Configuration changes
    pyproject.toml
    Bump version to 0.0.48                                                                     

    pyproject.toml

    • Updated the version from 0.0.47 to 0.0.48.
    +1/-1     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @github-actions github-actions bot added enhancement Enhancement to existing features Bug fix Review effort [1-5]: 2 labels Jun 20, 2024
    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review [1-5] 2
    🧪 Relevant tests No
    🔒 Security concerns No
    ⚡ Key issues to review Possible Bug:
    The change in error handling from raising a ValueError to logging a warning and deleting the index might introduce issues if other parts of the application rely on the exception for flow control or error handling.

    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Replace the warning log with an error log and raise an exception to ensure proper error handling

    Consider maintaining the original error handling by raising an exception instead of just
    logging a warning when a route is not found. This ensures that the caller can handle the
    error appropriately rather than proceeding with potentially undefined behavior.

    semantic_router/layer.py [437-438]

    -logger.warning(err_msg)
    -self.index.delete(route_name=route_name)
    +logger.error(err_msg)
    +raise ValueError(err_msg)
     
    Suggestion importance[1-10]: 9

    Why: This suggestion addresses a potential bug by ensuring that the error is properly handled through an exception, which is crucial for preventing undefined behavior.

    9
    Performance
    Improve the efficiency of the route existence check

    Refactor the list comprehension used to check if route_name exists in self.routes to a
    more efficient method using any(), which stops iterating as soon as a match is found,
    improving performance.

    semantic_router/layer.py [435]

    -if route_name not in [route.name for route in self.routes]:
    +if not any(route.name == route_name for route in self.routes):
     
    Suggestion importance[1-10]: 8

    Why: The suggestion improves performance by using a more efficient method to check for the existence of a route, which is beneficial for large datasets.

    8
    Enhancement
    Prevent unnecessary index operations by checking route existence before deletion

    Ensure that the deletion operation on self.index is only performed if the route actually
    exists. This prevents unnecessary operations on self.index which might lead to errors or
    unwanted side effects.

    semantic_router/layer.py [438]

    -self.index.delete(route_name=route_name)
    +if any(route.name == route_name for route in self.routes):
    +    self.index.delete(route_name=route_name)
     
    Suggestion importance[1-10]: 7

    Why: This suggestion enhances the code by preventing unnecessary operations, which can help avoid potential errors or side effects.

    7
    Maintainability
    Enhance the error message with additional context for better debugging

    Update the error message to include more context about the error, such as the specific
    layer where the route was not found, which can be helpful for debugging.

    semantic_router/layer.py [436]

    -err_msg = f"Route `{route_name}` not found in RouteLayer"
    +err_msg = f"Route `{route_name}` not found in RouteLayer of {self.__class__.__name__}"
     
    Suggestion importance[1-10]: 6

    Why: Adding more context to the error message can improve maintainability and debugging, although it is a minor enhancement.

    6

    Copy link

    codecov bot commented Jun 20, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 71.98%. Comparing base (3c7d1fc) to head (fca53a6).

    Additional details and impacted files
    @@           Coverage Diff           @@
    ##             main     #333   +/-   ##
    =======================================
      Coverage   71.98%   71.98%           
    =======================================
      Files          45       45           
      Lines        2920     2920           
    =======================================
      Hits         2102     2102           
      Misses        818      818           

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    @jamescalam jamescalam merged commit 8e6966e into main Jun 20, 2024
    8 checks passed
    @jamescalam jamescalam deleted the james/route-delete-hotfix branch June 20, 2024 08:48
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Bug fix enhancement Enhancement to existing features Review effort [1-5]: 2
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant