Open 9n opened 1 week ago
The issue with the Conditional Router
not stopping correctly and causing the input message to display twice, followed by an "Error parsing message," is likely due to a problem in the iterate_and_stop_once
method. The method is supposed to stop the opposite route when the maximum number of iterations is reached, but it seems to be incorrectly implemented.
Here's the relevant part of the code:
def iterate_and_stop_once(self, route_to_stop: str):
if not self.__iteration_updated:
self.update_ctx({f"{self._id}_iteration": self.ctx.get(f"{self._id}_iteration", 0) + 1})
self.__iteration_updated = True
if self.ctx.get(f"{self._id}_iteration", 0) >= self.max_iterations and route_to_stop == self.default_route:
# We need to stop the other route
route_to_stop = "true_result" if route_to_stop == "false_result" else "false_result"
self.stop(route_to_stop)
The problem arises because the route_to_stop
is being reassigned to the opposite route when the maximum iterations are reached, but the stop
method is still called with the original route_to_stop
value. This means that the intended route to stop is not being stopped, leading to the message being processed twice.
To fix this, the stop
method should be called with the updated route_to_stop
value:
def iterate_and_stop_once(self, route_to_stop: str):
if not self.__iteration_updated:
self.update_ctx({f"{self._id}_iteration": self.ctx.get(f"{self._id}_iteration", 0) + 1})
self.__iteration_updated = True
if self.ctx.get(f"{self._id}_iteration", 0) >= self.max_iterations and route_to_stop == self.default_route:
# We need to stop the other route
route_to_stop = "true_result" if route_to_stop == "false_result" else "false_result"
self.stop(route_to_stop) # Ensure this uses the updated route_to_stop
This change ensures that the correct route is stopped, preventing the message from being processed twice and avoiding the "Error parsing message" [1].
To continue talking to Dosu, mention @dosu.
Hi, I have the same question. It happened in both of version 1.0.17 and 1.1.0
I change the conditional Router with self.stop('method_name')
, but the components of the subsequent process will still be executed.
def true_response(self) -> Message:
result = self.evaluate_condition(self.input_text, self.match_text, self.operator, self.case_sensitive)
if result:
return self.message
else:
self.stop('true_response')
With the workflow:
20241114_debug_conditional_router.json 20241114_debug_conditional_router_v2.json
1.input=A, expected_output=A, real_output=A None None
2.input=B, expected_output=B, real_output=None B None
Still not work in this version: 20241114_debug_conditional_router_v2_使用langflow1.1.0版本.json
@joaoguilhermeS - I have given the details.
https://github.com/langflow-ai/langflow/issues/4590#issuecomment-2475895886
Bug Description
Conditional Router
does not stop correctly. The input message display twice, followed by a error message: "Error parsing message". It's not reproduced every time, try more times.Reproduction
hello
in the playgroundExpected behavior
return
hi, there I'm a robot
directly and no error messageWho can help?
No response
Operating System
manjaro
Langflow Version
v1.0.19.post2
Python Version
None
Screenshot
Flow File
Simple Conditional Router.json