Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Dataclass nodes made from a decorator are not pickleable #319

Open
liamhuber opened this issue May 9, 2024 · 0 comments
Open

🐛 Dataclass nodes made from a decorator are not pickleable #319

liamhuber opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@liamhuber
Copy link
Member

The easy bit is that when coming from a decorator, they need the same flag as the macro and function nodes from a decorator _class_returns_from_decorated_function (although it's a class in this case, not a function, so I guess the flag needs a better name). Adding cls._class_returns_from_decorated_function = dataclass to as_dataclass_node is sufficient to resolve this, __reduce__ then returns factory._instantiate_from_decorated and the problem is resolved in exactly the same manner as functions and macros.

The outstanding problem is that the underlying dataclass also gets used by the output signal, and there it's an instance property rather than a class property, so pickle tries to deal with it in the __getstate__ of the output channel and throws a it's not the same object as error.

I did a brute-force check and just setting {dataclass node}.outputs.dataclass.type_hint = None resolves this, so that really is the issue. In principle one could do this in the get- and set-state of dataclass nodes... but that's not a pattern I'm thrilled with.

Dataclass nodes instantiated separately from their dataclass instance pickle fine, of course. Maybe this is the better way to go anyhow, so that if/when you want to make new dataclasses by composition you don't wind up with something ugly like

@as_dataclass_node
@dataclass
class CompositeData(Parent.dataclass, Parent2.dataclass):
    pass
@liamhuber liamhuber added the bug Something isn't working label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant