reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Investigate dynamic var default value

Open picklelo opened this issue 3 years ago β€’ 0 comments

In @Lendemor's work in dynamic vars, we encountered an issue that the default value for the dynamic vars is always None.

@classmethod
def _set_default_value(cls, prop: BaseVar, default_value: Any = None):
    """Set the default value for the var.

    Args:
       prop: The var to set the default value for.
    """
    # Get the pydantic field for the var.
    field = cls.get_fields()[prop.name]
    default_value = default_value if default_value else prop.get_default_value()
    if field.required and default_value is not None:
        field.required = False
        field.default = default_value

Setting the default value here doesn't work.

picklelo avatar Jan 26 '23 09:01 picklelo