Skip to content

An optional dataclass set from None gets no child parameters, so its fields cannot be edited #48

Open

Description

@trissim

What happens at 1fcdf12: the flat parameter table is built from the instance the state is given. A field extra: Optional[Inner] = None gets the one parameter extra and no extra.depth. After update_parameter("extra", Inner()), _dataclass_parameter_updates (src/objectstate/object_state.py:822-842) returns {} because no path under extra. is registered (:828-833), so the children never appear: update_parameter("extra.depth", 5) hits the unknown-parameter branch (:941-946), logs a warning and does nothing. Going the other way, setting a populated optional dataclass to None leaves its child parameters registered and holding the old values.

A form therefore cannot offer "set / not set" for an optional group and then edit the group's fields through the same state.

Wanted: the parameters under an optional dataclass follow its value: registered (with types, defaults and saved baseline) when it becomes an instance, removed when it becomes None, with one change notification covering the paths that appeared or went.

Workaround in Toad now: none; toad.forms has no view for OptionalDataclassInfo and raises LookupError when a declaration asks for one.

Acceptance: with extra: Optional[Inner] = None, update_parameter("extra", Inner()) followed by update_parameter("extra.depth", 5) gives to_object().extra == Inner(depth=5); update_parameter("extra", None) then leaves no extra.* key in parameters or dirty_fields.

Activity

  1. trissim commented on Oct 12, 2026

    @trissim
    ContributorAuthor

    Measured for the other direction at 1fcdf12, with extra: Optional[Inner] = field(default_factory=Inner): after update_parameter("extra.depth", 5) then update_parameter("extra", None), parameters is {"extra": None, "extra.depth": 5}, dirty_fields is {"extra.depth"} (no extra), and to_object() returns R(extra=Inner(depth=5)): the None is stored but the object is rebuilt from the children, so an optional dataclass cannot be cleared either. The acceptance check should also assert to_object().extra is None after the clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions