[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
This commit is contained in:
Masen Furer 2024-12-10 09:46:19 -08:00
parent 49a8f813fe
commit ce364e0bce
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95

View File

@ -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.