Skip to content

Replace deprecated asyncio.get_event_loop() with asyncio.get_running_loop() in Snowflake search tool - #8915

Open
LVsarff wants to merge 1 commit into
crewAIInc:mainfrom
LVsarff:fix/crewai-tools-get-running-loop
Open

LVsarff wants to merge 1 commit into
crewAIInc:mainfrom
LVsarff:fix/crewai-tools-get-running-loop

Conversation

@LVsarff

@LVsarff LVsarff commented Nov 1, 2026 •

Copy link
Copy Markdown

Summary

asyncio.get_event_loop() is deprecated since Python 3.12 (and raises RuntimeError in Python 3.14 when no current loop exists). In coroutine contexts the recommended replacement is asyncio.get_running_loop(), which returns exactly the same loop with no deprecation.

Changes

One-line, behavior-identical replacement in lib/crewai-tools:

  • src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py — _get_connection() is an async def, so a loop is always running when await asyncio.get_running_loop().run_in_executor(...) is reached.

Note: the Snowflake tool's sibling stagehand_tool.py uses get_event_loop() in sync bridge methods; that pattern requires a slightly larger refactor (handling the no-running-loop case), so it is intentionally left out of this minimal PR.

Verification

  • py_compile passes
  • ruff check --no-fix reports no new findings on the changed line (existing findings in this file are pre-existing and untouched)

Fixes #8912

Note: this PR supersedes #8911, which was submitted without an issue reference and auto-closed by the first-time-contributor gate as a result (reopen is not permitted for external contributors).

LLM disclosure

This change was prepared with the assistance of an AI coding agent and reviewed before submission. Per the repository's contribution guidelines, please add the llm-generated label to this PR if appropriate (I don't have permission to add labels myself).


Note

Low Risk
Single-line asyncio API swap in an async method with no logic or connection-handling changes.

Overview
Updates SnowflakeSearchTool._get_connection() so that when the connection pool is empty, blocking Snowflake connection creation still runs via run_in_executor, but the event loop is obtained with asyncio.get_running_loop() instead of the deprecated asyncio.get_event_loop().

This is a behavior-preserving change for Python 3.12+ (and avoids RuntimeError when no loop is set in 3.14), because _get_connection is only called from async code paths where a loop is already running.

Reviewed by Cursor Bugbot for commit 2b079d0. Bugbot is set up for automated code reviews on this repo. Configure here.

@strix-security

strix-security Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: Replaces `asyncio.get_event_loop()` with `asyncio.get_running_loop()` in the Snowflake search tool's async connection helper to avoid the Python 3.12+ deprecation, with no behavior change since a loop is always running in that coroutine.

Review summary

The PR makes a single-line, semantics-preserving change in the Snowflake search tool, replacing the deprecated asyncio.get_event_loop() with asyncio.get_running_loop() inside the async def _get_connection coroutine. I read the diff together with the surrounding implementation: credential handling (password via SecretStr, private-key file loading), connection-pool locking, and query/cache construction are all untouched, and no changed line introduces or removes an input-handling, authorization, or secret-handling control. No security issues found in the changed code.

Review 1 on this PR · 2b079d0 · requested Nov 1 13:22 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings

This branch has not been deployed

No deployments
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.

[BUG] Deprecated asyncio.get_event_loop() calls in lib/crewai and lib/crewai-tools

1 participant