Skip to content

Commit 4cf6303

Browse files
make state contextmanager a no-op by default, drop config option
1 parent 86896fe commit 4cf6303

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

reflex/environment.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,6 @@ class EnvironmentVariables:
727727
# How long to wait between automatic reload on frontend error to avoid reload loops.
728728
REFLEX_AUTO_RELOAD_COOLDOWN_TIME_MS: EnvVar[int] = env_var(10_000)
729729

730-
# Whether to allow entering a state mutation with `async with self` in normal (non background) event handlers
731-
REFLEX_STATE_ALLOW_CONTEXTMANAGER_WITHOUT_BACKGROUND_TASK: EnvVar[bool] = env_var(
732-
False
733-
)
734-
735730

736731
environment = EnvironmentVariables()
737732

reflex/state.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,19 +2189,12 @@ def dict(
21892189
async def __aenter__(self) -> BaseState:
21902190
"""Enter the async context manager protocol.
21912191
2192-
This should not be used for the State class, but exists for
2193-
type-compatibility with StateProxy.
2192+
This is a no-op for the State class and mainly used in background-tasks/StateProxy.
21942193
21952194
Returns:
21962195
The unmodified state (self)
2197-
2198-
Raises:
2199-
TypeError: always, because async contextmanager protocol is only supported for background task.
22002196
"""
2201-
if environment.REFLEX_STATE_ALLOW_CONTEXTMANAGER_WITHOUT_BACKGROUND_TASK.get():
2202-
return self
2203-
msg = "Only background task should use `async with self` to modify state."
2204-
raise TypeError(msg)
2197+
return self
22052198

22062199
async def __aexit__(self, *exc_info: Any) -> None:
22072200
"""Exit the async context manager protocol.

0 commit comments

Comments
 (0)