From b742afb27f0e5e5e60e2afc5aedaefa87206ce88 Mon Sep 17 00:00:00 2001 From: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com> Date: Mon, 1 Jul 2024 19:17:40 +0200 Subject: [PATCH] do not get_config in global scope (#3597) * do not get_config in global scope * ruff fixes * pydantic v1 compatibility --- reflex/state.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/reflex/state.py b/reflex/state.py index 69270b24a..88eb7ae73 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -61,7 +61,6 @@ if TYPE_CHECKING: Delta = Dict[str, Any] var = computed_var -config = get_config() # If the state is this large, it's considered a performance issue. @@ -2319,6 +2318,24 @@ def _dill_reduce_state(pickler, obj): dill.Pickler.dispatch[type](pickler, obj) +def _default_lock_expiration() -> int: + """Get the default lock expiration time. + + Returns: + The default lock expiration time. + """ + return get_config().redis_lock_expiration + + +def _default_token_expiration() -> int: + """Get the default token expiration time. + + Returns: + The default token expiration time. + """ + return get_config().redis_token_expiration + + class StateManagerRedis(StateManager): """A state manager that stores states in redis.""" @@ -2326,10 +2343,10 @@ class StateManagerRedis(StateManager): redis: Redis # The token expiration time (s). - token_expiration: int = config.redis_token_expiration + token_expiration: int = pydantic.Field(default_factory=_default_token_expiration) # The maximum time to hold a lock (ms). - lock_expiration: int = config.redis_lock_expiration + lock_expiration: int = pydantic.Field(default_factory=_default_lock_expiration) # The keyspace subscription string when redis is waiting for lock to be released _redis_notify_keyspace_events: str = (