Comparison between outer rx.foreach item and inner rx.foreach item is always false
Closed this issue · 1 comments
giacomochiarella commented
Describe the bug
When a nested foreach uses comparison between element of its iterator and element in the outer foreach iterator, it evaluates always to false.
To Reproduce
The following code evaluates always to false
class MyState:
my_outer_list: list[list[Any]] = [[0, "a", "b"], [1, "c", "d"]]
my_inner_dict: dict[int, list[list[Any]]] = {0: [["e", "f"]], 1: [["g", "h"]]}
rx.foreach(
SupersetState.my_outer_list,
lambda o: rx.foreach(
SupersetState.my_inner_dict,
lambda i: rx.text(i[0], o[0], i[0] == o[0])
)
)
It renders:
00false
10false
01false
11false
Expected behavior
I expect the comparison evaluates correctly: true when both operands are the same, false otherwise
Screenshots
Specifics (please complete the following information):
- Python Version: 3.10
- Reflex Version: 0.8.9
- OS: Docker container
- Browser (Optional):
Additional context
adhami3310 commented
if you do:
rx.foreach(
SupersetState.my_outer_list,
lambda o: rx.foreach(
SupersetState.my_inner_dict,
lambda i: rx.text(i[0].to_string(), o[0].to_string(), i[0] == o[0]),
),
)you are going to find out that outputs:
"0"0false
"1"0false
"0"1false
"1"1false
which is because in JSON, keys cannot be integers, so the dict keys got converted into strings through network