Skip to content

Commit

Permalink
Use ._is_mutable() to account for parent state proxy (#3739)
Browse files Browse the repository at this point in the history
When a parent state proxy is set, also allow child StateProxy._self_mutable to
override the parent's `_is_mutable()`.
  • Loading branch information
masenf authored Aug 5, 2024
1 parent 7d9ed7e commit 3309c0e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,7 @@ def _is_mutable(self) -> bool:
Whether the state is mutable.
"""
if self._self_parent_state_proxy is not None:
return self._self_parent_state_proxy._is_mutable()
return self._self_parent_state_proxy._is_mutable() or self._self_mutable
return self._self_mutable

async def __aenter__(self) -> StateProxy:
Expand Down Expand Up @@ -3302,7 +3302,7 @@ def _mark_dirty(
Raises:
ImmutableStateError: if the StateProxy is not mutable.
"""
if not self._self_state._self_mutable:
if not self._self_state._is_mutable():
raise ImmutableStateError(
"Background task StateProxy is immutable outside of a context "
"manager. Use `async with self` to modify state."
Expand Down

0 comments on commit 3309c0e

Please sign in to comment.