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

Collection in Database action #1104

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

nupur-khare
Copy link
Contributor

@nupur-khare nupur-khare commented Jan 2, 2024

  1. Added field 'collection' in DatabaseActionRequest.
  2. Fixed test cases.

Summary by CodeRabbit

  • New Features

    • Introduced a new attribute to enhance database action requests with collection validation.
  • Bug Fixes

    • Adjusted data cleaning logic for improved stability and reliability.
  • Refactor

    • Updated methods to ensure proper collection name validation before performing database actions.
  • Tests

    • Expanded integration and unit tests to cover new functionality and changes in database action creation and execution.

Copy link

coderabbitai bot commented Jan 2, 2024

Walkthrough

Walkthrough

The update introduces a new collection attribute to the DatabaseActionRequest class and ensures it is validated before use. It also revises the data cleaning logic in DataObject and adds checks in processor files to verify collection linkage before performing database actions. Additionally, test suites have been updated to reflect these changes, specifically incorporating the collection parameter and adjusting to the new error handling.

Changes

File Path Change Summary
kairon/api/models.py Added collection attribute and validate_collection_name to DatabaseActionRequest.
kairon/shared/actions/data_objects.py Removed clean method; updated data cleaning logic.
kairon/shared/.../processor.py Imported DatabaseAction, updated validate_collection_name with collection checks.
kairon/shared/data/processor.py Added CognitionSchema import, updated update_db_action and add_db_action with collection checks.
tests/integration_test/.../action_service_test.py
tests/integration_test/services_test.py
Updated DatabaseAction constructor calls with collection parameter; modified test cases and assertions.
tests/unit_test/data_processor/.../data_processor_test.py Switched to CognitionDataProcessor, updated instances and tests related to database action modifications.

Poem

🐰 "In the realm of code, where data arrays sprawl,
A rabbit hopped in, to tidy it all.
With each collection named, no detail too small,
Ensuring no action would err or appall." 🌟

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 with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ef69c62 and d6cce93.
Files selected for processing (7)
  • kairon/api/models.py (2 hunks)
  • kairon/shared/actions/data_objects.py (1 hunks)
  • kairon/shared/cognition/processor.py (2 hunks)
  • kairon/shared/data/processor.py (3 hunks)
  • tests/integration_test/action_service_test.py (12 hunks)
  • tests/integration_test/services_test.py (18 hunks)
  • tests/unit_test/data_processor/data_processor_test.py (22 hunks)
Additional comments: 44
kairon/shared/cognition/processor.py (2)
  • 9-9: The addition of the DatabaseAction import is correct and necessary for the subsequent use within the file.

  • 247-254: The changes to the validate_collection_name method correctly introduce a check for DatabaseAction objects associated with the collection, preventing the removal of a collection that is linked to a database action.

kairon/shared/actions/data_objects.py (1)
  • 200-204: The removal of the clean method from the DataObject class alters the data cleaning logic. Verify that this change does not negatively impact data validation and cleaning processes elsewhere in the system.
kairon/api/models.py (1)
  • 406-411: The addition of the collection field to the DatabaseActionRequest class is consistent with the PR's objective to enhance database action functionality. Ensure that the collection field is being utilized wherever DatabaseActionRequest instances are created or processed.
kairon/shared/data/processor.py (3)
  • 97-97: Added import for CognitionSchema from ..cognition.data_objects.

  • 3214-3224: In the update_db_action method, ensure that the CognitionSchema with the given collection name exists before proceeding to update the collection attribute of the DatabaseAction. This helps maintain data integrity by linking actions to valid collections.

  • 3239-3251: In the add_db_action method, ensure that the CognitionSchema with the given collection name exists before proceeding to add a new DatabaseAction. This helps maintain data integrity by linking actions to valid collections.

tests/integration_test/action_service_test.py (12)
  • 2893-2893: The addition of the collection parameter to the DatabaseAction constructor is consistent with the PR objectives to enhance database action functionality. Ensure that the collection value used here is valid and exists in the database.

  • 2902-2902: The update to the http_url variable reflects the new collection parameter. Verify that the updated URL is correct and the server is configured to handle requests to this new endpoint.

  • 2985-2985: The addition of the collection parameter with a different value suggests testing against various collections. Verify that this collection name is also valid and exists.

  • 2994-2994: The http_url update is consistent with the new collection parameter. Verify the correctness of the updated URL as with the previous hunk.

  • 3061-3061: The collection parameter is added with yet another unique value, indicating a thorough test coverage for different collections. Verify the existence and validity of this collection as well.

  • 3070-3070: The http_url is updated to match the new collection parameter. As before, ensure the updated URL is correct and reachable.

  • 3147-3147: The addition of the collection parameter here is consistent with the pattern observed in other hunks. Verify the collection name for validity.

  • 3156-3156: The http_url update matches the new collection parameter. Verify the correctness of the updated URL.

  • 3220-3220: The collection parameter is added, which is in line with the PR objectives. Verify the collection name for validity.

  • 3230-3230: The http_url is updated to reflect the new collection parameter. Verify the correctness of the updated URL.

  • 3305-3305: The collection parameter is added, but the query_type is set to a string rather than using the DbActionOperationType enum. This could be an inconsistency or error. Verify if query_type should be an enum value for consistency with other test cases.

  • 3366-3366: The collection parameter is added consistently with other test cases. Verify the collection name for validity.

tests/integration_test/services_test.py (20)
  • 7259-7259: The addition of the "collection" field in the request body is consistent with the PR's objective to enhance database actions. Ensure that the test case test_add_vectordb_action_empty_name is updated to reflect the new field requirement.

  • 7277-7281: The test case test_add_vectordb_action_empty_collection_name correctly checks for an empty collection name. However, ensure that the test case name is unique and not a duplicate as mentioned in the AI-generated summary.

  • 7294-7294: The assertion for the error message is correct and aligns with the expected validation for the "collection" field. This ensures that the error messages are descriptive and helpful for debugging.

  • 7314-7317: The assertions for the error message in test_add_vectordb_action_empty_operation_value are specific and check for the correct enumeration values, which is a good practice for validation tests.

  • 7349-7349: The test case test_add_vectordb_action_empty_payload_value is updated to include the "collection" field. Ensure that the test case is checking for the correct behavior when the payload value is empty.

  • 7367-7392: The test case test_add_vectordb_action_collection_does_not_exists is well-structured to check the scenario where the collection does not exist. The assertions for the error code and message are appropriate.

  • 7364-7426: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [7395-7457]

The test case test_add_vectordb_action includes a mock setup and a sequence of API calls to test the addition of a vectordb action. The assertions check for both success and failure scenarios, which is a comprehensive approach.

  • 7460-7463: The test case test_add_vectordb_action_case_insensitivity should verify that the collection name is case-insensitive. Ensure that the test case is designed to validate this behavior.

  • 7509-7509: The test case test_add_vectordb_action_existing is updated to include the "collection" field. Verify that the test case is intended to check the behavior when adding an existing vectordb action.

  • 7553-7553: The test case test_add_vectordb_action_with_slots includes the "collection" field. Ensure that the test case is checking for the correct behavior when using slots in the payload.

  • 7574-7574: The test case test_update_vectordb_action is updated to include the "collection" field. Verify that the test case is intended to check the update functionality for vectordb actions.

  • 7597-7597: The test case test_update_vectordb_action is updated to include the "collection" field. Verify that the test case is intended to check the update functionality for vectordb actions.

  • 7625-7625: The test case test_update_vectordb_action_non_existing is updated to include the "collection" field. Verify that the test case is intended to check the update functionality for non-existing vectordb actions.

  • 7640-7640: The test case test_update_vectordb_action_non_existing is updated to include the "collection" field. Verify that the test case is intended to check the update functionality for non-existing vectordb actions.

  • 7661-7661: The test case test_update_vector_action_wrong_parameter is updated to include the "collection" field. Verify that the test case is intended to check the behavior when an incorrect parameter is used in the vectordb action.

  • 7678-7678: The test case test_update_vector_action_wrong_parameter is updated to include the "collection" field. Verify that the test case is intended to check the behavior when an incorrect parameter is used in the vectordb action.

  • 7726-7726: The assertion in test_list_vector_db_action checks for the correct name of the vectordb action. This is a good practice to ensure that the list functionality is working as expected.

  • 7730-7732: The test case test_delete_vectordb_action is updated to include the "collection" field. Verify that the test case is intended to check the delete functionality for vectordb actions.

  • 7765-7765: The test case test_delete_vectordb_action_non_existing is updated to include the "collection" field. Verify that the test case is intended to check the delete functionality for non-existing vectordb actions.

  • 8646-8649: The assertion in test_list_actions checks for the correct names of vectordb actions. This is a good practice to ensure that the list functionality is working as expected and that the new "collection" field is being considered.

tests/unit_test/data_processor/data_processor_test.py (5)
  • 9595-9596: The introduction of both CognitionDataProcessor and MongoProcessor may indicate a transition phase or compatibility layer. Ensure that the use of both processors is intentional and that their respective roles within the tests are clear and justified.

  • 9629-9629: The add_db_action method is called on processor_two, which is an instance of MongoProcessor. Confirm that this is consistent with the intended usage of MongoProcessor in the context of the new CognitionDataProcessor changes.

  • 9638-9640: The test case correctly expects an AppException when trying to delete a schema linked to an action. Ensure that the message in the match parameter of pytest.raises is consistent with the actual error message produced by the system for such cases.

  • 9679-9688: The creation of CognitionSchema and CognitionData with the new collection field appears consistent across the hunks. Ensure that the collection field is being used as intended and that the test cases cover all necessary scenarios related to this new field.

  • 9786-9787: The test case correctly expects an AppException when adding a database action to a non-existent collection. Verify that the error message in the match parameter of pytest.raises aligns with the actual error message for non-existent collections.

Comment on lines +422 to +428
@validator("collection")
def validate_collection_name(cls, v, values, **kwargs):
from kairon.shared.utils import Utility

if Utility.check_empty_string(v):
raise ValueError("collection is required")
return v
Copy link

Choose a reason for hiding this comment

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

The validate_collection_name method correctly checks for an empty collection string. However, consider also validating the format of the collection name if there are specific naming conventions or restrictions in the database system being used.

@validator("collection")
def validate_collection_name(cls, v, values, **kwargs):
    from kairon.shared.utils import Utility

    if Utility.check_empty_string(v):
        raise ValueError("collection is required")
    # Example additional validation for format (if applicable)
    if not re.match("^[a-zA-Z0-9_]+$", v):
        raise ValueError("collection name contains invalid characters")
    return v

@@ -9865,6 +9965,7 @@ def test_get_vector_embedding_action_does_not_exists(self):
payload = {'type': 'from_slot', 'value': 'email'}
DatabaseAction(
name=action,
collection='test_get_vector_embedding_action_does_not_exists',
Copy link

Choose a reason for hiding this comment

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

This test case seems to be missing the assertion or exception handling for the creation of a DatabaseAction with a non-existent collection. Ensure that the test case is complete and accurately reflects the expected behavior when dealing with non-existent collections.

Copy link
Contributor

@udit-pandey udit-pandey left a comment

Choose a reason for hiding this comment

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

approved

@udit-pandey udit-pandey merged commit 44fc36f into digiteinfotech:master Jan 2, 2024
7 checks passed
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.

2 participants