From 473bde940cdff292cfec289a21bffed506b501ca Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 29 Jun 2023 15:17:23 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(loading.py):=20add=20error?= =?UTF-8?q?=20handling=20for=20missing=20'cursor'=20attribute=20in=20insta?= =?UTF-8?q?ntiate=5Fmemory=20function=20The=20instantiate=5Fmemory=20funct?= =?UTF-8?q?ion=20now=20includes=20error=20handling=20for=20a=20specific=20?= =?UTF-8?q?AttributeError=20that=20occurs=20when=20the=20object=20does=20n?= =?UTF-8?q?ot=20have=20a=20'cursor'=20attribute.=20If=20this=20error=20occ?= =?UTF-8?q?urs,=20an=20AttributeError=20is=20raised=20with=20a=20specific?= =?UTF-8?q?=20error=20message=20indicating=20a=20failure=20to=20build=20a?= =?UTF-8?q?=20connection=20to=20the=20database.=20This=20change=20improves?= =?UTF-8?q?=20the=20error=20handling=20and=20provides=20more=20informative?= =?UTF-8?q?=20error=20messages=20for=20debugging=20purposes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/interface/initialize/loading.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/langflow/interface/initialize/loading.py b/src/backend/langflow/interface/initialize/loading.py index 65461f141..8503290b1 100644 --- a/src/backend/langflow/interface/initialize/loading.py +++ b/src/backend/langflow/interface/initialize/loading.py @@ -82,10 +82,25 @@ def instantiate_based_on_type(class_object, base_type, node_type, params): return instantiate_llm(node_type, class_object, params) elif base_type == "retrievers": return instantiate_retriever(node_type, class_object, params) + elif base_type == "memory": + return instantiate_memory(node_type, class_object, params) else: return class_object(**params) +def instantiate_memory(node_type, class_object, params): + try: + return class_object(**params) + # I want to catch a specific attribute error that happens + # when the object does not have a cursor attribute + except AttributeError as exc: + if "object has no attribute 'cursor'" in str(exc): + raise AttributeError( + f"Failed to build connection to database. Please check your connection string and try again. Error: {exc}" + ) from exc + raise exc + + def instantiate_retriever(node_type, class_object, params): if "retriever" in params and hasattr(params["retriever"], "as_retriever"): params["retriever"] = params["retriever"].as_retriever()