Skip to content

Commit

Permalink
[core][graphIO] PartialSerializer: fix List/GroupAttribute link seria…
Browse files Browse the repository at this point in the history
…lization

Ensure attribute input connection is serialized, even for List/GroupAttributes.
Note: while connecting GroupAttributes is not yet supported, this will benefit
this type of attribute once it is.
  • Loading branch information
yann-lty committed Feb 6, 2025
1 parent 724e7fb commit 0594f59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions meshroom/core/graphIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,13 @@ def _serializeAttribute(self, attribute: Attribute) -> Any:
Serialize `attribute` (recursively for list/groups) and deal with attributes being connected
to nodes that are not part of the partial list of nodes to serialize.
"""
# If the attribute is connected to a node that is not in the list of nodes to serialize,
# the link expression should not be serialized.
if attribute.isLink and attribute.getLinkParam().node not in self.nodes:
linkParam = attribute.getLinkParam()

if linkParam is not None:
# Use standard link serialization if upstream node is part of the serialization.
if linkParam.node in self.nodes:
return attribute.getExportValue()
# Skip link serialization otherwise.
# If part of a list, this entry can be discarded.
if isinstance(attribute.root, ListAttribute):
return None
Expand Down
14 changes: 14 additions & 0 deletions tests/test_graphIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ def test_serializeAllNodesIsSimilarToStandardSerialization(self):
assert compareGraphsContent(graph, graphA)
assert compareGraphsContent(graphA, graphB)

def test_listAttributeToListAttributeConnectionIsSerialized(self):
graph = Graph("")

with registeredNodeTypes([NodeWithListAttributes]):
nodeA = graph.addNewNode(NodeWithListAttributes.__name__)
nodeB = graph.addNewNode(NodeWithListAttributes.__name__)

graph.addEdge(nodeA.listInput, nodeB.listInput)

otherGraph = Graph("")
otherGraph._deserialize(graph.serializePartial([nodeA, nodeB]))

assert otherGraph.node(nodeB.name).listInput.linkParam == otherGraph.node(nodeA.name).listInput

def test_singleNodeWithInputConnectionFromNonSerializedNodeRemovesEdge(self):
graph = Graph("")

Expand Down

0 comments on commit 0594f59

Please sign in to comment.