reflex-dev/reflex · error · ValueError

No default value or factory provided.

Error message

No default value or factory provided.

What it means

Raised by Field.get_default() when neither a default value nor a default_factory was provided — there is nothing to return.

Source

Thrown at packages/reflex-base/src/reflex_base/vars/base.py:3572

            for key, value in source_field.__dict__.items():
                if key not in self.__dict__ and key not in _RESERVED_FIELD_ATTRS:
                    self.__dict__[key] = value

    def default_value(self) -> FIELD_TYPE | None:
        """Get the default value for the field.

        Returns:
            The default value for the field.

        Raises:
            ValueError: If no default value or factory is provided.
        """
        if self.default is not MISSING:
            return self.default
        if self.default_factory is not None:
            return self.default_factory()
        msg = "No default value or factory provided."
        raise ValueError(msg)

    def __repr__(self) -> str:
        """Represent the field in a readable format.

        Returns:
            The string representation of the field.
        """
        annotated_type_str = (
            f", annotated_type={self.annotated_type!r}"
            if self.annotated_type is not MISSING
            else ""
        )
        if self.default is not MISSING:
            return f"Field(default={self.default!r}, is_var={self.is_var}{annotated_type_str})"
        return f"Field(default_factory={self.default_factory!r}, is_var={self.is_var}{annotated_type_str})"

    if TYPE_CHECKING:

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Provide default=... or default_factory=... when creating the Field
  2. Skip calling get_default() when both default and default_factory are unset (check field.default is MISSING and default_factory is None first)

Example fix

# before
field = rx.Field(ge=0)
value = field.get_default()
# after
field = rx.Field(default=0, ge=0)
value = field.get_default()
Defensive patterns

Strategy: validation

Validate before calling

if field.default is MISSING and field.default_factory is None:
    raise ValueError('field has no default')
value = field.get_default()

Try / catch

try:
    value = field.get_default()
except ValueError:
    value = None  # or skip this field

Prevention

When it happens

Trigger: Calling .get_default() on a Field created with rx.Field() (or dataclasses.field equivalent) with no default/default_factory, typically during state initialization or serialization.

Common situations: Custom state fields introspected generically; a Field built only with constraints (gt=, ge=...) and no default, then asked for its default.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/878a463d24914834. Report an issue: GitHub.