|
35 | 35 | from reflex.istate.manager.redis import StateManagerRedis |
36 | 36 | from reflex.state import ( |
37 | 37 | BaseState, |
| 38 | + ImmutableMutableProxy, |
38 | 39 | ImmutableStateError, |
39 | 40 | MutableProxy, |
40 | 41 | OnLoadInternalState, |
@@ -4419,20 +4420,30 @@ async def test_rebind_mutable_proxy(mock_app: rx.App, token: str) -> None: |
4419 | 4420 | "token": token, |
4420 | 4421 | "sid": "test_sid", |
4421 | 4422 | }) |
| 4423 | + assert isinstance(state, MutableProxyState) |
| 4424 | + assert isinstance(state.data, MutableProxy) |
| 4425 | + assert not isinstance(state.data, ImmutableMutableProxy) |
4422 | 4426 | state_proxy = StateProxy(state) |
4423 | | - assert isinstance(state_proxy.data, MutableProxy) |
| 4427 | + assert isinstance(state_proxy.data, ImmutableMutableProxy) |
4424 | 4428 | async with state_proxy: |
| 4429 | + # This assigns an ImmutableMutableProxy to data["a"]. |
4425 | 4430 | state_proxy.data["a"] = state_proxy.data["b"] |
| 4431 | + assert isinstance(state_proxy.data["a"], ImmutableMutableProxy) |
4426 | 4432 | assert state_proxy.data["a"] is not state_proxy.data["b"] |
4427 | 4433 | assert state_proxy.data["a"].__wrapped__ is state_proxy.data["b"].__wrapped__ |
4428 | 4434 |
|
| 4435 | + # Rebinding with a non-proxy should return a MutableProxy object (not ImmutableMutableProxy). |
| 4436 | + assert isinstance(state_proxy.__wrapped__.data["a"], MutableProxy) |
| 4437 | + assert not isinstance(state_proxy.__wrapped__.data["a"], ImmutableMutableProxy) |
| 4438 | + |
4429 | 4439 | # Flush any oplock. |
4430 | 4440 | await mock_app.state_manager.close() |
4431 | 4441 |
|
4432 | 4442 | new_state_proxy = StateProxy(state) |
4433 | 4443 | assert state_proxy is not new_state_proxy |
4434 | 4444 | assert new_state_proxy.data["a"]._self_state is new_state_proxy |
4435 | 4445 | assert state_proxy.data["a"]._self_state is state_proxy |
| 4446 | + assert state_proxy.__wrapped__.data["a"]._self_state is state_proxy.__wrapped__ |
4436 | 4447 |
|
4437 | 4448 | async with state_proxy: |
4438 | 4449 | state_proxy.data["a"].append(3) |
|
0 commit comments