fix: replace deprecated asyncio.get_event_loop() with get_running_loop()#12124
fix: replace deprecated asyncio.get_event_loop() with get_running_loop()#12124gambletan wants to merge 1 commit intolangflow-ai:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <[email protected]>
WalkthroughTwo files were updated to replace Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 2 warnings, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/backend/base/langflow/main.py (1)
192-194: Reset the timer before the unconditional superuser init.Line 194 is still measuring against the previous
current_time. That makes this startup metric inaccurate: it includes the prior block whenAUTO_LOGINis enabled, and can include unrelated earlier work when it is disabled.⏱️ Proposed fix
await logger.adebug("Initializing super user") + current_time = asyncio.get_running_loop().time() await initialize_auto_login_default_superuser() await logger.adebug(f"Super user initialized in {asyncio.get_running_loop().time() - current_time:.2f}s")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/backend/base/langflow/main.py` around lines 192 - 194, The elapsed-time log for the unconditional superuser init is using an earlier current_time, so before calling logger.adebug("Initializing super user") and initialize_auto_login_default_superuser() reset the timer by assigning current_time = asyncio.get_running_loop().time(); then use that current_time in the later logger.adebug(f"Super user initialized in {asyncio.get_running_loop().time() - current_time:.2f}s") to measure only the superuser initialization; the relevant symbols to update are logger.adebug and initialize_auto_login_default_superuser and the asyncio.get_running_loop().time() call.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/backend/base/langflow/main.py`:
- Around line 192-194: The elapsed-time log for the unconditional superuser init
is using an earlier current_time, so before calling logger.adebug("Initializing
super user") and initialize_auto_login_default_superuser() reset the timer by
assigning current_time = asyncio.get_running_loop().time(); then use that
current_time in the later logger.adebug(f"Super user initialized in
{asyncio.get_running_loop().time() - current_time:.2f}s") to measure only the
superuser initialization; the relevant symbols to update are logger.adebug and
initialize_auto_login_default_superuser and the
asyncio.get_running_loop().time() call.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 794d8688-b7c7-414c-bc68-794ad6556cb3
📒 Files selected for processing (2)
src/backend/base/langflow/main.pysrc/lfx/src/lfx/base/mcp/util.py
|
Good catch on the stale |
Summary
asyncio.get_event_loop()calls withasyncio.get_running_loop()in two files:src/backend/base/langflow/main.py(30 occurrences in the asynclifespancontext manager)src/lfx/src/lfx/base/mcp/util.py(4 occurrences in async methods ofMCPSessionManager)Motivation
asyncio.get_event_loop()has been deprecated since Python 3.10 and emits aDeprecationWarningwhen called without a running event loop. Since Langflow requires Python >= 3.10, and all call sites in this PR are insideasyncfunctions (where a running loop is guaranteed),asyncio.get_running_loop()is the correct replacement.get_running_loop()is also safer: it raises aRuntimeErrorif no loop is running, rather than silently creating a new one—making bugs easier to catch.Test plan
async deffunctions, soget_running_loop()will always find the running loop🤖 Generated with Claude Code
Summary by CodeRabbit