From 3c7ecd15f75ac85e0fcf592f8163609ccec17c65 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 3 Jul 2023 23:27:49 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(validate.py):=20check=20if?= =?UTF-8?q?=20variable=20is=20already=20in=20the=20list=20before=20appendi?= =?UTF-8?q?ng=20and=20remove=20variable=20from=20custom=5Ffields=20and=20t?= =?UTF-8?q?emplate=20when=20not=20in=20input=5Fvariables=20The=20code=20no?= =?UTF-8?q?w=20checks=20if=20the=20variable=20is=20already=20in=20the=20li?= =?UTF-8?q?st=20before=20appending=20it=20to=20the=20custom=5Ffields.=20Ad?= =?UTF-8?q?ditionally,=20when=20removing=20old=20variables=20from=20the=20?= =?UTF-8?q?template,=20the=20code=20now=20also=20removes=20the=20variable?= =?UTF-8?q?=20from=20the=20custom=5Ffields=20associated=20with=20the=20giv?= =?UTF-8?q?en=20name.=20This=20ensures=20that=20the=20custom=5Ffields=20an?= =?UTF-8?q?d=20template=20stay=20in=20sync=20with=20the=20input=5Fvariable?= =?UTF-8?q?s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/validate.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/api/v1/validate.py b/src/backend/langflow/api/v1/validate.py index 7c9279801..36870af35 100644 --- a/src/backend/langflow/api/v1/validate.py +++ b/src/backend/langflow/api/v1/validate.py @@ -75,9 +75,15 @@ def add_new_variables_to_template(input_variables, prompt_request): ) prompt_request.frontend_node.template[variable] = template_field.to_dict() - prompt_request.frontend_node.custom_fields[prompt_request.name].append( + + # Check if variable is not already in the list before appending + if ( variable - ) + not in prompt_request.frontend_node.custom_fields[prompt_request.name] + ): + prompt_request.frontend_node.custom_fields[prompt_request.name].append( + variable + ) except Exception as exc: logger.exception(exc) @@ -90,7 +96,18 @@ def remove_old_variables_from_template( for variable in old_custom_fields: if variable not in input_variables: try: + # Remove the variable from custom_fields associated with the given name + if ( + variable + in prompt_request.frontend_node.custom_fields[prompt_request.name] + ): + prompt_request.frontend_node.custom_fields[ + prompt_request.name + ].remove(variable) + + # Remove the variable from the template prompt_request.frontend_node.template.pop(variable, None) + except Exception as exc: logger.exception(exc) raise HTTPException(status_code=500, detail=str(exc)) from exc