From aca19ef54f3b0bc58fefede60683b61fe3107cda Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 21 Feb 2024 17:39:54 -0300 Subject: [PATCH] Refactor Vertex class to handle code parsing and string unescaping --- src/backend/langflow/graph/vertex/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index e76bd714e..cd8d7e141 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -244,7 +244,7 @@ class Vertex: for key, value in self.data["node"]["template"].items() if isinstance(value, dict) } - params = self.params.copy() if self.params else {} + params = {} for edge in self.edges: if not hasattr(edge, "target_param"): @@ -287,8 +287,7 @@ class Vertex: if value.get("type") == "code": try: params[key] = ast.literal_eval(val) if val else None - except Exception as exc: - logger.debug(f"Error parsing code: {exc}") + except Exception: params[key] = val elif value.get("type") in ["dict", "NestedDict"]: # When dict comes from the frontend it comes as a @@ -312,6 +311,10 @@ class Vertex: params[key] = float(val) except ValueError: params[key] = val + elif value.get("type") == "str" and val is not None: + # val may contain escaped \n, \t, etc. + # so we need to unescape it + params[key] = val.encode().decode("unicode_escape") elif val is not None and val != "": params[key] = val