ComposioHQ / composio

Composio equip's your AI agents & LLMs with 100+ high-quality integrations via function calling
https://docs.composio.dev
Other
7.47k stars 2.33k forks source link

Update sql query tool #344

Closed kaavee315 closed 1 month ago

kaavee315 commented 1 month ago

PR Type

Enhancement, Error handling


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
sql_query.py
Enhance SQL query tool with error handling and file existence check

python/composio/tools/local/sqltool/actions/sql_query.py
  • Added check for database file existence before attempting connection.
  • Wrapped database operations in try-except block to handle SQLite
    errors.
  • Ensured database connection is closed in a finally block.
  • +27/-11 

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

    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review: 2 ๐Ÿ”ต๐Ÿ”ตโšชโšชโšช
    ๐Ÿงช No relevant tests
    ๐Ÿ”’ No security concerns identified
    โšก Key issues to review

    Error Handling
    The error handling in the try-except block captures SQLite errors but does not log them or provide a mechanism to notify the system of the error other than returning it in the response. Consider logging errors or implementing a more robust error handling strategy. Resource Leak
    The connection is only closed if it exists in the local variables, which might not cover all cases where the connection was opened but an error occurred before adding it to locals(). Consider initializing 'connection' before the try block to ensure it's always closed in the finally block.
    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Best practice
    โœ… Use the with statement to manage the database connection for better resource handling ___
    Suggestion Impact:The commit implemented the suggestion to use the 'with' statement for managing the database connection, ensuring that the connection is properly closed even if an error occurs. code diff: ```diff + # Use 'with' statement to manage the database connection + with sqlite3.connect(request_data.connection_string) as connection: + cursor = connection.cursor() - # Execute the query - cursor.execute(request_data.query) + # Execute the query + cursor.execute(request_data.query) - response_data = cursor.fetchall() - connection.commit() + response_data = cursor.fetchall() + connection.commit() ```
    ___ **To ensure that the database connection is always closed, even in case of an error
    before the connection is established, use the with statement for managing the
    database connection.** [python/composio/tools/local/sqltool/actions/sql_query.py [51-70]](https://github.com/ComposioHQ/composio/pull/344/files#diff-303d52cebfa2d739b67e5fcde4d48cf6943e36f9dc96455bef66e389c99976c0R51-R70) ```diff -connection = sqlite3.connect(request_data.connection_string) -cursor = connection.cursor() -... -if "connection" in locals(): - connection.close() +with sqlite3.connect(request_data.connection_string) as connection: + cursor = connection.cursor() + ... ```
    Suggestion importance[1-10]: 9 Why: Using the `with` statement ensures that the database connection is properly closed even if an error occurs, which enhances resource management and code reliability.
    9
    Maintainability
    โœ… Add error logging in the exception handling block to improve error traceability ___
    Suggestion Impact:The commit added error logging in the exception handling block, which aligns with the suggestion to improve error traceability. code diff: ```diff except sqlite3.Error as e: + print(f"SQLite error: {str(e)}") + ```
    ___ **Add error logging for the catch block to aid in debugging and maintaining logs for
    errors that occur during database operations.** [python/composio/tools/local/sqltool/actions/sql_query.py [63-65]](https://github.com/ComposioHQ/composio/pull/344/files#diff-303d52cebfa2d739b67e5fcde4d48cf6943e36f9dc96455bef66e389c99976c0R63-R65) ```diff except sqlite3.Error as e: + logging.error(f"SQLite error: {str(e)}") return { "execution_details": {"executed": False}, "response_data": f"SQLite error: {str(e)}" } ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Adding error logging helps in debugging and maintaining logs for errors, which is crucial for monitoring and troubleshooting issues in production environments.
    8
    Enhancement
    โœ… Replace os.path.exists with pathlib.Path.exists for checking file existence ___
    Suggestion Impact:The commit replaced os.path.exists with pathlib.Path.exists to check if the database file exists, as suggested. code diff: ```diff - import os + from pathlib import Path # Check if the database file exists - if not os.path.exists(request_data.connection_string): + if not Path(request_data.connection_string).exists(): ```
    ___ **Instead of using os.path.exists to check if the database file exists, consider using
    pathlib.Path.exists for a more modern and object-oriented approach.** [python/composio/tools/local/sqltool/actions/sql_query.py [43]](https://github.com/ComposioHQ/composio/pull/344/files#diff-303d52cebfa2d739b67e5fcde4d48cf6943e36f9dc96455bef66e389c99976c0R43-R43) ```diff -if not os.path.exists(request_data.connection_string): +from pathlib import Path +if not Path(request_data.connection_string).exists(): ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Using `pathlib.Path.exists` is a more modern and object-oriented approach, which can improve code readability and maintainability. However, it does not significantly impact the functionality.
    7
    codiumai-pr-agent-pro[bot] commented 1 month ago

    CI Failure Feedback ๐Ÿง

    (Checks updated until commit https://github.com/ComposioHQ/composio/commit/c05e978d5384247b38f8ae4e2a893441c788cfc3)

    **Action:** test (ubuntu-latest, 3.9)
    **Failed stage:** [Unittests](https://github.com/ComposioHQ/composio/actions/runs/10023044607/job/27703518166) [โŒ]
    **Failed test name:** test_action_enum
    **Failure summary:** The action failed because the test test_action_enum in the file tests/test_client/test_enum.py
    raised a ValueError.
  • The error message was: "Invalid value GITHUB_ISSUES_LIST for Action".
  • This indicates that the value GITHUB_ISSUES_LIST is not a valid entry for the Action enum.
  • Relevant error logs: ```yaml 1: ##[group]Operating System 2: Ubuntu ... 504: * [new branch] fix/rag-agent -> origin/fix/rag-agent 505: * [new branch] fix/readme -> origin/fix/readme 506: * [new branch] fix/readme-logo -> origin/fix/readme-logo 507: * [new branch] fix/swe-agent -> origin/fix/swe-agent 508: * [new branch] ft-add-better-help-text -> origin/ft-add-better-help-text 509: * [new branch] ft-apps-id -> origin/ft-apps-id 510: * [new branch] ft-bring-back-core-sdk -> origin/ft-bring-back-core-sdk 511: * [new branch] ft-did-you-mean -> origin/ft-did-you-mean 512: * [new branch] ft-error-tracking -> origin/ft-error-tracking ... 932: tests/test_cli/test_actions.py::TestListActions::test_list_all[arguments3-exptected_outputs3-unexptected_outputs3] PASSED [ 17%] 933: tests/test_cli/test_actions.py::TestListActions::test_tag_not_found PASSED [ 19%] 934: tests/test_cli/test_actions.py::TestListActions::test_limit SKIPPED [ 21%] 935: tests/test_cli/test_actions.py::TestListActions::test_copy PASSED [ 23%] 936: tests/test_cli/test_add.py::TestComposioAdd::test_no_auth PASSED [ 25%] 937: tests/test_cli/test_apps.py::TestList::test_list PASSED [ 27%] 938: tests/test_cli/test_apps.py::TestUpdate::test_update_not_required PASSED [ 29%] 939: tests/test_cli/test_apps.py::TestUpdate::test_update SKIPPED (Needs 940: investigation, this test fails in CI) [ 31%] ... 948: tests/test_client/test_client.py::test_raise_invalid_api_key PASSED [ 48%] 949: tests/test_client/test_collections.py::TestTriggerNamesSerialization::test_converts_trigger_objects_to_comma_separated_string PASSED [ 51%] 950: tests/test_client/test_collections.py::TestTriggerNamesSerialization::test_converts_trigger_strings_to_comma_separated_string PASSED [ 53%] 951: tests/test_client/test_collections.py::TestTriggerNamesSerialization::test_converts_mix_of_trigger_objects_and_strings PASSED [ 55%] 952: tests/test_client/test_collections.py::test_trigger_subscription PASSED [ 57%] 953: tests/test_client/test_endpoints.py::test_endpoint PASSED [ 59%] 954: tests/test_client/test_enum.py::test_tag_enum PASSED [ 61%] 955: tests/test_client/test_enum.py::test_app_enum PASSED [ 63%] 956: tests/test_client/test_enum.py::test_action_enum FAILED [ 65%] ... 965: tests/test_tools/test_local/test_workspace.py::test_stderr PASSED [ 85%] 966: tests/test_tools/test_local/test_workspace.py::test_workspace PASSED [ 87%] 967: tests/test_utils/test_decorators.py::test_deprecated PASSED [ 89%] 968: tests/test_utils/test_git.py::test_get_git_user_info PASSED [ 91%] 969: tests/test_utils/test_shared.py::test_get_pydantic_signature_format_from_schema_params PASSED [ 93%] 970: tests/test_utils/test_shared.py::test_json_schema_to_pydantic_field PASSED [ 95%] 971: tests/test_utils/test_shared.py::test_json_schema_to_fields_dict PASSED [ 97%] 972: tests/test_utils/test_url.py::test_get_web_url PASSED [100%] 973: =================================== FAILURES =================================== ... 983: self = 984: value = 'GITHUB_ISSUES_LIST' 985: def __init__(self, value: t.Union[str, te.Self]) -> None: 986: """Create an Enum""" 987: if isinstance(value, _AnnotatedEnum): 988: value = value._slug 989: value = t.cast(str, value).upper() 990: if value not in self.__annotations__ and value not in _runtime_actions: 991: > raise ValueError(f"Invalid value `{value}` for `{self.__class__.__name__}`") 992: E ValueError: Invalid value `GITHUB_ISSUES_LIST` for `Action` 993: composio/client/enums/base.py:112: ValueError ... 998: .tox/unittests/lib/python3.9/site-packages/paramiko/pkey.py:100 999: /home/runner/work/composio/composio/python/.tox/unittests/lib/python3.9/site-packages/paramiko/pkey.py:100: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0. 1000: "cipher": algorithms.TripleDES, 1001: .tox/unittests/lib/python3.9/site-packages/paramiko/transport.py:259 1002: /home/runner/work/composio/composio/python/.tox/unittests/lib/python3.9/site-packages/paramiko/transport.py:259: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0. 1003: "class": algorithms.TripleDES, 1004: .tox/unittests/lib/python3.9/site-packages/pydantic/_internal/_config.py:291 1005: .tox/unittests/lib/python3.9/site-packages/pydantic/_internal/_config.py:291 1006: /home/runner/work/composio/composio/python/.tox/unittests/lib/python3.9/site-packages/pydantic/_internal/_config.py:291: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/ ... 1196: composio/utils/shared.py 118 84 29% 44, 47-51, 54-58, 61-77, 83, 101-104, 153-158, 174-221, 247-293 1197: composio/utils/url.py 10 1 90% 35 1198: examples/crewai_ci_chart.py 14 14 0% 1-38 1199: -------------------------------------------------------------------------------------------------------------- 1200: TOTAL 9890 2268 77% 1201: Coverage HTML written to dir htmlcov 1202: Coverage XML written to file coverage.xml 1203: =========================== short test summary info ============================ 1204: FAILED tests/test_client/test_enum.py::test_action_enum - ValueError: Invalid value `GITHUB_ISSUES_LIST` for `Action` 1205: ============= 1 failed, 41 passed, 5 skipped, 5 warnings in 41.66s ============= 1206: unittests: exit 1 (42.69 seconds) /home/runner/work/composio/composio/python> pytest -vvv -rfE --doctest-modules composio/ tests/ --cov=composio --cov=examples --cov-report=html --cov-report=xml --cov-report=term --cov-report=term-missing --cov-config=.coveragerc pid=5695 1207: .pkg: _exit> python /opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__ 1208: unittests: FAIL code 1 (85.96=setup[37.58]+cmd[5.68,42.69] seconds) 1209: evaluation failed :( (86.17 seconds) 1210: ##[error]Process completed with exit code 1. ```

    โœจ CI feedback usage guide:
    The CI feedback tool (`/checks)` automatically triggers when a PR has a failed check. The tool analyzes the failed checks and provides several feedbacks: - Failed stage - Failed test name - Failure summary - Relevant error logs In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR: ``` /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}" ``` where `{repo_name}` is the name of the repository, `{run_number}` is the run number of the failed check, and `{job_number}` is the job number of the failed check. #### Configuration options - `enable_auto_checks_feedback` - if set to true, the tool will automatically provide feedback when a check is failed. Default is true. - `excluded_checks_list` - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list. - `enable_help_text` - if set to true, the tool will provide a help message with the feedback. Default is true. - `persistent_comment` - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true. - `final_update_message` - if `persistent_comment` is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true. See more information about the `checks` tool in the [docs](https://pr-agent-docs.codium.ai/tools/ci_feedback/).