taipy icon indicating copy to clipboard operation
taipy copied to clipboard

BUG-Multi-user fails when state.data["X"] = ...

Open AlexandreSajus opened this issue 1 year ago • 2 comments

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()
  1. Run the app in browser A
  2. Connect to the app in an incognito page B
  3. Press the button in browser A
  4. Refresh incognito page B
  5. 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

AlexandreSajus avatar Oct 25 '23 09:10 AlexandreSajus

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.

AlexandreSajus avatar Oct 25 '23 09:10 AlexandreSajus

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"]]}
    )

AlexandreSajus avatar Oct 25 '23 09:10 AlexandreSajus

Is it released in Taipy 3.1.1? I seem to have the same issue with dict.

FlorianJacta avatar Apr 23 '24 09:04 FlorianJacta