Skip to content

Commit

Permalink
[core] Handle missing link nodes when deserializing edges
Browse files Browse the repository at this point in the history
Avoid uncaught errors when deserializing edges in case linked
nodes are missing.
Handle missing nodes the same way missing attributes are dealt with.
  • Loading branch information
yann-lty committed Jan 28, 2025
1 parent 0d5aa6c commit f224afc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions meshroom/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,12 @@ def _applyExpr(self):
elif self.isInput and Attribute.isLinkExpression(v):
# value is a link to another attribute
link = v[1:-1]
linkNode, linkAttr = link.split('.')
linkNodeName, linkAttrName = link.split('.')
try:
g.addEdge(g.node(linkNode).attribute(linkAttr), self)
node = g.node(linkNodeName)
if not node:
raise KeyError(f"Node '{linkNodeName}' not found")
g.addEdge(node.attribute(linkAttrName), self)
except KeyError as err:
logging.warning('Connect Attribute from Expression failed.')
logging.warning('Expression: "{exp}"\nError: "{err}".'.format(exp=v, err=err))
Expand Down
12 changes: 12 additions & 0 deletions tests/test_graphIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,15 @@ def test_nodeWithoutVersionInfoIsUpgraded(self):
assert len(graph.nodes) == 1
assert len(graph.compatibilityNodes) == 0

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

with registeredNodeTypes([SimpleNode]):
sampleGraphContent = dedent("""
{
"SimpleNode_1": {
"nodeType": "SimpleNode", "inputs": { "input": "{NotSerializedNode.output}" }
}
}
""")
graph._deserialize(json.loads(sampleGraphContent))

0 comments on commit f224afc

Please sign in to comment.