Skip to content

SplitContainer.content setter orphans current content when the assignment is invalid #4631

Description

@Dev9269

Summary

SplitContainer.content setter detaches the currently-shown widgets before validating the new value (core/src/toga/widgets/splitcontainer.py):

python @content.setter def content(self, content): for old_content in self._content: if old_content is not None: old_content.app = None old_content.window = None try: if len(content) != 2: raise TypeError() ...

If the assignment is invalid (wrong length, duplicate widget, wrong type), the exception propagates but the old content was already orphaned � its app/window set to None. The widget tree then holds a SplitContainer with no children, while the previously-visible widgets are detached but still referenced externally.

Expected behavior

A failed content assignment should leave the current content attached and untouched.

Actual behavior

Invalid assignment empties the SplitContainer and orphans the previous content (e.g., widgets disappear from app.widgets even though content still reports the old value).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA crash or error in behavior.

    Projects

    Status
    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions