Skip to content

fix(traits): hand a trait its saved state back on load - #5590

Merged
collindutter merged 0 commit into
fix/minmax-multiline-ui-optionfrom
fix/trait-state-reaches-the-trait
Sep 22, 2026
Merged

collindutter merged 0 commit into
fix/minmax-multiline-ui-optionfrom
fix/trait-state-reaches-the-trait

Conversation

@collindutter

@collindutter collindutter commented Sep 18, 2026

Copy link
Copy Markdown
Member

A save restored trait-rendered ui_options but left the live trait at its constructor defaults, so the editor could show max_val=50 while Slider still accepted 80. Stateful traits now expose plain save/load hooks, and the engine applies state to the instance built by node code so callbacks and other wiring remain intact:

class Threshold(Trait):
    def to_state(self) -> dict[str, int]:
        return {"level": self.level}

    def apply_state(self, state: dict[str, int]) -> None:
        if "level" in state:
            self.level = state["level"]

Closes #5440. Refs #5442.


📚 Documentation preview 📚: https://griptape-nodes--5590.org.readthedocs.build/en/5590/

Comment thread tests/unit/traits/test_trait_state_round_trip.py Fixed
Comment thread tests/unit/traits/test_trait_state_round_trip.py Fixed
Comment thread tests/unit/traits/test_trait_field_declarations.py Fixed
Comment thread tests/unit/traits/test_trait_field_declarations.py Fixed
Comment thread tests/unit/traits/test_trait_field_declarations.py Fixed
Comment thread tests/unit/traits/test_trait_field_declarations.py Fixed
Comment thread tests/unit/traits/test_trait_field_declarations.py Fixed
Comment thread tests/unit/traits/test_trait_field_declarations.py Fixed
Comment thread tests/unit/traits/test_trait_field_declarations.py Fixed
Comment thread tests/unit/traits/test_trait_field_declarations.py Fixed
from griptape_nodes.traits.slider import Slider


class Twin(Trait):
_ALLOWED_LEVEL = 2


class Ranged(Trait):
Comment thread tests/unit/retained_mode/managers/test_trait_state_serialization.py Fixed
Comment thread tests/unit/traits/test_trait_ui_option_adoption.py Fixed
Comment thread tests/unit/traits/test_trait_ui_option_adoption.py Fixed
]


class _UnsaveableValueTrait(Trait):
assert any("items" in r.getMessage() for r in caplog.records if r.levelno == logging.WARNING)


class _RequiredCallbackTrait(Trait):
@collindutter
collindutter force-pushed the fix/trait-state-reaches-the-trait branch from c057bb1 to 418a9a6 Compare September 22, 2026 22:55
@collindutter
collindutter merged commit 418a9a6 into main Sep 22, 2026
3 of 4 checks passed
@collindutter
collindutter deleted the fix/trait-state-reaches-the-trait branch September 22, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Options.choices sync to Parameter.ui_options is a no-op against a computed property

1 participant