From ce364e0bcee402d0e57767c0ffe218b7e1bc2afd Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Tue, 10 Dec 2024 09:46:19 -0800 Subject: [PATCH] [ENG-4165] Consider default and default_factory for state vars When determining whether a state var should be marked as optional, check that it is missing both default and default_factory and is not required. Fix #4471 --- reflex/state.py | 1 + 1 file changed, 1 insertion(+) diff --git a/reflex/state.py b/reflex/state.py index c86bd9a1b..f3491d3d5 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -1081,6 +1081,7 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow): if ( not field.required and field.default is None + and field.default_factory is None and not types.is_optional(prop._var_type) ): # Ensure frontend uses null coalescing when accessing.