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

Serialization of graph fails if there are accepted_connection_types/rejected_connection_types defined #434

Open
claudio-alvaro-wbgames opened this issue Oct 2, 2024 · 2 comments

Comments

@claudio-alvaro-wbgames
Copy link

Python's json doesn't serialize set objects. I unfortunately can't submit a PR but the fix is relatively simple, in case anyone else encounters this issue.

line 553 of NodeGraphQt/base/model.py:

        if accept_ptype not in connection_data:
            connection_data[accept_ptype] = [accept_pname]
        else:
            # ensure data remains a set instead of list after json de-serialize
            connection_data[accept_ptype] = list(set(connection_data[accept_ptype]) | {accept_pname})
jchanvfx added a commit that referenced this issue Oct 6, 2024
jchanvfx added a commit that referenced this issue Oct 6, 2024
@jchanvfx
Copy link
Owner

jchanvfx commented Oct 6, 2024

@claudio-alvaro-wbgames Thanks for pointing out this issue I'll make some tweaks.

@dberlin
Copy link

dberlin commented Jan 3, 2025

So i just reworked the code to just serialize the accepted/rejected constraints directly as they appear.
IE

serialization is
# connection constrains. serial_data['graph']['accept_connection_types'] = self.model.accept_connection_types serial_data['graph']['reject_connection_types'] = self.model.reject_connection_types
deserialization is
# connection constrains. elif attr_name == 'accept_connection_types': self.model.accept_connection_types = attr_value elif attr_name == 'reject_connection_types': self.model.reject_connection_types = attr_value

This works fine.

If you are worried about storing it like this, I would just serialize it as a tuple of arguments for add_{accept, reject}_port_type and replay them on deserialization.

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

No branches or pull requests

3 participants