You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An optional dataclass set from None gets no child parameters, so its fields cannot be edited #48
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.
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.
Activity
trissim commentedon Oct 12, 2026
Measured for the other direction at 1fcdf12, with
extra: Optional[Inner] = field(default_factory=Inner): afterupdate_parameter("extra.depth", 5)thenupdate_parameter("extra", None),parametersis{"extra": None, "extra.depth": 5},dirty_fieldsis{"extra.depth"}(noextra), andto_object()returnsR(extra=Inner(depth=5)): theNoneis stored but the object is rebuilt from the children, so an optional dataclass cannot be cleared either. The acceptance check should also assertto_object().extra is Noneafter the clear.