backend vars logic is now supported

This commit is contained in:
Elijah 2024-10-03 08:35:00 +00:00
parent bb8d7c5d15
commit c51d6752c6
2 changed files with 8 additions and 11 deletions

View File

@ -1282,9 +1282,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
return return
if ( if (
not name.startswith( not name.startswith("__")
"_" and not name.startswith(f"_{type(self).__name__}__")
) # TODO: skipping backend vars and vars with double leading underscores for now. They should be supported, however.
and name not in self.vars and name not in self.vars
and name not in self.get_skip_vars() and name not in self.get_skip_vars()
): ):

View File

@ -41,6 +41,7 @@ from reflex.state import (
) )
from reflex.testing import chdir from reflex.testing import chdir
from reflex.utils import format, prerequisites, types from reflex.utils import format, prerequisites, types
from reflex.utils.exceptions import SetUndefinedStateVarError
from reflex.utils.format import json_dumps from reflex.utils.format import json_dumps
from reflex.vars.base import ComputedVar, Var from reflex.vars.base import ComputedVar, Var
from tests.units.states.mutation import MutableSQLAModel, MutableTestState from tests.units.states.mutation import MutableSQLAModel, MutableTestState
@ -3293,17 +3294,14 @@ def test_assignment_to_undeclared_vars():
state = State() # type: ignore state = State() # type: ignore
sub_state = Substate() # type: ignore sub_state = Substate() # type: ignore
with pytest.raises(AttributeError): with pytest.raises(SetUndefinedStateVarError):
state.handle_regular_var() state.handle_regular_var()
with pytest.raises(AttributeError): with pytest.raises(SetUndefinedStateVarError):
sub_state.handle_var() sub_state.handle_var()
# TODO: uncomment this if the case of backend vars are supported. with pytest.raises(SetUndefinedStateVarError):
# with pytest.raises(AttributeError): state.handle_backend_var()
# state.handle_backend_var()
#
# with pytest.raises(AttributeError):
# state.handle_non_var()
state.handle_supported_regular_vars() state.handle_supported_regular_vars()
state.handle_non_var()