From 6db20a16421aad19063151a66d6c9065d2c28d07 Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 12 Aug 2024 17:44:56 -0300 Subject: [PATCH 1/3] fix: Corrected URI handling in SQLDatabaseComponent --- .../langchain_utilities/SQLDatabase.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py b/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py index e9c7565d6e47..6ddb754f60d9 100644 --- a/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py +++ b/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py @@ -1,7 +1,7 @@ -from langchain_experimental.sql.base import SQLDatabase - +from langchain_community.utilities.sql_database import SQLDatabase from langflow.custom import CustomComponent - +from sqlalchemy import create_engine +from sqlalchemy.pool import StaticPool class SQLDatabaseComponent(CustomComponent): display_name = "SQLDatabase" @@ -13,11 +13,7 @@ def build_config(self): "uri": {"display_name": "URI", "info": "URI to the database."}, } - def clean_up_uri(self, uri: str) -> str: - if uri.startswith("postgresql://"): - uri = uri.replace("postgresql://", "postgres://") - return uri.strip() - def build(self, uri: str) -> SQLDatabase: - uri = self.clean_up_uri(uri) - return SQLDatabase.from_uri(uri) + # Create an engine using SQLAlchemy with StaticPool + engine = create_engine(uri, poolclass=StaticPool) + return SQLDatabase(engine) From de4f503b631614a53c628513dcb678c2453a3053 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 20:59:29 +0000 Subject: [PATCH 2/3] [autofix.ci] apply automated fixes --- .../base/langflow/components/langchain_utilities/SQLDatabase.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py b/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py index 6ddb754f60d9..c22c04167e8d 100644 --- a/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py +++ b/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py @@ -3,6 +3,7 @@ from sqlalchemy import create_engine from sqlalchemy.pool import StaticPool + class SQLDatabaseComponent(CustomComponent): display_name = "SQLDatabase" description = "SQL Database" From af905f50f42fbbaedaf409ddb892cac66deac25b Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 12 Aug 2024 18:51:40 -0300 Subject: [PATCH 3/3] Add URI cleanup and SQLAlchemy engine creation to SQLDatabaseComponent --- .../langflow/components/langchain_utilities/SQLDatabase.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py b/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py index c22c04167e8d..4d5104aabd00 100644 --- a/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py +++ b/src/backend/base/langflow/components/langchain_utilities/SQLDatabase.py @@ -14,7 +14,13 @@ def build_config(self): "uri": {"display_name": "URI", "info": "URI to the database."}, } + def clean_up_uri(self, uri: str) -> str: + if uri.startswith("postgres://"): + uri = uri.replace("postgres://", "postgresql://") + return uri.strip() + def build(self, uri: str) -> SQLDatabase: + uri = self.clean_up_uri(uri) # Create an engine using SQLAlchemy with StaticPool engine = create_engine(uri, poolclass=StaticPool) return SQLDatabase(engine)