Преглед на файлове

do not get_config in global scope (#3597)

* do not get_config in global scope

* ruff fixes

* pydantic v1 compatibility
benedikt-bartscher преди 10 месеца
родител
ревизия
b742afb27f
променени са 1 файла, в които са добавени 20 реда и са изтрити 3 реда
  1. 20 3
      reflex/state.py

+ 20 - 3
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 = (