This commit is contained in:
benedikt-bartscher 2025-01-25 22:25:07 +00:00 committed by GitHub
commit 17b096a385
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 0 deletions

View File

@ -703,6 +703,9 @@ class Config(Base):
# Path to file containing key-values pairs to override in the environment; Dotenv format.
env_file: Optional[str] = None
# Whether to only make rx.Field annotated state attributes base vars
state_explicit_vars: bool = False
def __init__(self, *args, **kwargs):
"""Initialize the config values.

View File

@ -559,11 +559,17 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
**new_backend_vars,
}
from reflex.vars.base import Field
# Set the base and computed vars.
cls.base_vars = {
f.name: get_var_for_field(cls, f)
for f in cls.get_fields().values()
if f.name not in cls.get_skip_vars()
and (
not get_config().state_explicit_vars
or get_origin(f.outer_type_) is Field
)
}
cls.computed_vars = {
v._js_expr: v._replace(merge_var_data=VarData.from_state(cls))

View File

@ -692,6 +692,12 @@ def is_backend_base_variable(name: str, cls: Type) -> bool:
if hint == ClassVar:
return False
from reflex.config import get_config
from reflex.vars.base import Field
if get_config().state_explicit_vars and get_origin(hint) is not Field:
return False
if name in cls.inherited_backend_vars:
return False