File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed
Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -727,6 +727,11 @@ 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+ # Wheter 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+
730735
731736environment = EnvironmentVariables ()
732737
Original file line number Diff line number Diff line change @@ -2192,9 +2192,14 @@ async def __aenter__(self) -> BaseState:
21922192 This should not be used for the State class, but exists for
21932193 type-compatibility with StateProxy.
21942194
2195+ Returns:
2196+ The unmodified state (self)
2197+
21952198 Raises:
21962199 TypeError: always, because async contextmanager protocol is only supported for background task.
21972200 """
2201+ if environment .REFLEX_STATE_ALLOW_CONTEXTMANAGER_WITHOUT_BACKGROUND_TASK .get ():
2202+ return self
21982203 msg = "Only background task should use `async with self` to modify state."
21992204 raise TypeError (msg )
22002205
You can’t perform that action at this time.
0 commit comments