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

setting LANGFLOW_DATABASE_URL to a valid and available postgres instance can lead to error #5983

Open
ebachUTSA opened this issue Jan 28, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@ebachUTSA
Copy link

Bug Description

When installing langflow on a windows environment, if you set the LANGFLOW_DATABASE_URL to a valid and available postgres instance you may encounter the following asyncio related error:

2025-01-28 11:50:30.271 ERROR service.py 155 with_session Database error during session scope: (psycopg.InterfaceError) Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())'
(Background on this error at: https://sqlalche.me/e/20/rvf5)
2025-01-28 11:50:30.273 ERROR utils.py 76 initialize_database Error creating DB and tables

This is due to differences in how the Windows subsystem handles the Event Loop. I have provided the solution in the "Who can help" section below. I am only asking for it to implemented at your earliest convenience.

Reproduction

To reproduce this you must be on Windows (this bug is specific to a Windows environment):

1. Create a python venv: python -m venv ./menv
2. Initialize venv: ./menv/Scripts/activate
3. Install uv: pip install uv
4. Install langflow: uv pip install langflow
5. Edit your environment variables and set your databaseurl to an available postgres instance: "LANGFLOW_DATABASE_URL":"postgresql://username:password@localhost:5432/langflow" (NOTE this is just an example url, modify for your postgres instance)
6. Run langflow: langflow run

Expected behavior

The expected behavior is that Langflow will initialize the database in postgres. Unfortunately because windows might handle async operations different from *nix systems, an additional check and modification is necessary in the services.py file found under services/daatabase folder.

Add the following after the existing imports but before any other code (for me, this was lines 33:36 of the services.py file):

import sys

if sys.platform == "win32":
        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Who can help?

@italojohnny

Operating System

Windows 10

Langflow Version

1.1.2dev3 (langflow nightly)

Python Version

3.12

Screenshot

No response

Flow File

No response

@ebachUTSA ebachUTSA added the bug Something isn't working label Jan 28, 2025
Copy link

dosubot bot commented Jan 28, 2025

Hey @ebachUTSA! 👋 I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. I'm an expert bot and I'm at your service!

A similar issue was previously reported and closed: Langflow not starting with postgres - giving Sqlite error. This issue was resolved by a pull request that addressed a missing SQLite dialect [1].

For the current issue you're facing, the error is related to the event loop policy on Windows. The suggested solution is to modify the services.py file to set the event loop policy for Windows. You can add the following code after the existing imports:

import sys
import asyncio

if sys.platform == "win32":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

This change ensures that a compatible event loop is used on Windows, which should resolve the ProactorEventLoop error you're encountering.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant