fix(state): let a background handler call the one it overrides through super()
A background event handler that overrides one from a mixin or a parent state cannot extend it through super():
class SaveMixin(rx.State, mixin=True):
@rx.event(background=True)
async def save(self):
async with self:
...
class Editor(SaveMixin, rx.State):
@rx.event(background=True)
async def save(self):
async with self:
...
await super().save() # ImmutableStateError
In a background task self is the task's StateProxy. super().save hands that proxy to EventHandler.__get__, which walks parent_state through it to find the state the handler is bound to, and the proxy refuses any attribute read outside async with self:
ImmutableStateError: Background task StateProxy is immutable outside of a context manager. Use `async with self` to modify state.
For a mixin this worked in 0.10, when @rx.event left a plain function on the mixin; since 0.11 it is an EventHandler there too. For a handler of a parent state it has failed since #7312. The workaround is calling the underlying function, await super(Editor, type(self)).save.fn(self).
EventHandler.__get__ now hands a StateProxy instance to StateProxy._bind_overridden_handler, which binds the overridden function the way the proxy's own __getattr__ binds handlers: to the proxy itself for a mixin or the proxy's own state, or through _call_on_ancestor to the ancestor declaring it. It skips __getattr__'s guard against calling a background task directly, since the overriding handler extends the other one in its own task. reflex-base cannot import reflex.istate.proxy, so the proxy type is installed on EventHandler from there, the way Field._proxy gets MutableProxy. The check runs only when owner is not the instance's own type: attribute access always passes that type, while super() through a proxy passes the wrapped state's class, so looking up a handler on a state costs what it did before (the first commit's isinstance slowed test_state_access[get_handler] by 8.9%).
test_background_handler_extends_its_base_through_super covers a mixin and a parent state on every state manager; both raised ImmutableStateError before the fix.