taipy
taipy copied to clipboard
BUG-Multi-user fails when state.data["X"] = ...
Description
A user on Discord reported this. Multi-user and state-bound variables do not work properly when we modify data using state.data["X"] = ...
How to reproduce Using the following code:
from taipy.gui import Gui
data = {"X": range(1, 6), "Y": [x * x for x in range(1, 6)]}
page = """
<|{data}|table|show_all|rebuild|>
<|button|label=Double X and Y|on_action=double_x_and_y|>
"""
def double_x_and_y(state):
state.data["X"] = [2 * x for x in state.data["X"]]
state.data["Y"] = [2 * x for x in state.data["Y"]]
Gui(page=page).run()
- Run the app in browser A
- Connect to the app in an incognito page B
- Press the button in browser A
- Refresh incognito page B
- Incognito page B will show the data modified while no button has been pressed in B
Expected behavior Modifying data using slices should modify the state-bound variable, not the original one. Incognito page B should show the original data.
Runtime environment
- OS: Windows 11
- Browser: Chrome
- Taipy: 2.4.0
Another issue we found is this:
from taipy.gui import Gui
x_range = range(1, 6)
data = {"X": x_range, "Y": [x * x for x in x_range]}
page = """
<|{data}|table|show_all|rebuild|>
<|button|label=Double X and Y|on_action=double_x_and_y|>
"""
def double_x_and_y(state):
temp = state.data
temp["X"] = [2 * x for x in temp["X"]]
temp["Y"] = [2 * x for x in temp["Y"]]
state.data = temp
Gui(page=page).run()
Running this and pressing the button twice raises:
TaipyGuiWarning: on_action(): Exception raised in 'double_x_and_y()':
maximum recursion depth exceeded
TaipyGuiWarning: on_action(): 'double_x_and_y' is not a valid function.
Also, a workaround for this issue is this:
def double_x_and_y(state):
state.data = pd.DataFrame(
{"X": [x * 2 for x in state.data["X"]], "Y": [y * 2 for y in state.data["Y"]]}
)
Is it released in Taipy 3.1.1? I seem to have the same issue with dict.