Closed antoremin closed 1 month ago
Hey there, @antoremin! I'm here to help you with any bugs, questions, or contributions you might have. Let's tackle this together while we wait for a human maintainer.
To resolve the error "Error building component SQLDatabase: can't load plugin: sqlalchemy.dialects:postgres," you need to ensure that the PostgreSQL URI is correctly formatted. The clean_up_uri
method in the SQLDatabaseComponent
class replaces "postgresql://" with "postgres://", which is necessary because SQLAlchemy expects the URI to be in the format "postgres://".
Here is the relevant part of the code:
def clean_up_uri(self, uri: str) -> str:
if uri.startswith("postgresql://"):
uri = uri.replace("postgresql://", "postgres://")
return uri.strip()
Make sure your URI is correctly formatted using this method before passing it to the SQLDatabase.from_uri
method. This should resolve the error related to loading the PostgreSQL plugin.
Here is an example of how to use the SQLDatabaseComponent
to build the SQLDatabase:
from langchain_experimental.sql.base import SQLDatabase
class SQLDatabaseComponent:
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)
component = SQLDatabaseComponent()
uri = "postgresql://user:password@localhost/dbname"
database = component.build(uri)
This will ensure that the URI is cleaned up and correctly formatted, allowing the SQLDatabase utility to connect to the PostgreSQL database without encountering the plugin loading error [1][2].
To continue talking to Dosu, mention @dosu.
Hi @antoremin ,
Do you need any assistance with this case? If not, please let us know if this issue can be closed.
Hi @antoremin ,
Do you need any assistance with this case? If not, please let us know if this issue can be closed.
Actually I was having the same error yesterday.
If I have time I could checked that, depending on best of my knowledge replace is not solving the issue anymore.
@antoremin
I checked it out and the component seems outdated. It needs to be updated to the new model that the components are built on.
This solved my problem:
from langchain_experimental.sql.base import SQLDatabase
from langflow.interface.custom.custom_component import CustomComponent
class SQLDatabaseComponent(CustomComponent):
display_name = "SQLDatabase"
description = "SQL Database"
def build_config(self):
return {
"uri": {"display_name": "URI", "info": "URI to the database."},
}
#SQLAlchemy 1.4 removed the deprecated postgres dialect name, the name postgresql must be used instead now.
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)
return SQLDatabase.from_uri(uri)
@Alperemrehas Thank you!
Fixed here: https://github.com/langflow-ai/langflow/pull/3292
@Alperemrehas Thank you!
Fixed here: #3292
Thank you @carlosrcoelho .
Describe the bug I'm putting in a postgresql connection string and get an error: Error building component SQLDatabase: can't load plugin: sqlalchemy.dialects:postgres.
Browser and Version
To Reproduce Steps to reproduce the behavior:
Screenshots
Additional context If I'm not mistaken, sqlalchemy deprecated postgres and only allows postgresql dialect. Yet in Langflow SQLDatabase, SQLExecutor, etc, the postgresql URI is explicitly replaced with postgres: