Skip to content

Commit f224afc

Browse files
committed
[core] Handle missing link nodes when deserializing edges
Avoid uncaught errors when deserializing edges in case linked nodes are missing. Handle missing nodes the same way missing attributes are dealt with.
1 parent 0d5aa6c commit f224afc

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

meshroom/core/attribute.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,12 @@ def _applyExpr(self):
330330
elif self.isInput and Attribute.isLinkExpression(v):
331331
# value is a link to another attribute
332332
link = v[1:-1]
333-
linkNode, linkAttr = link.split('.')
333+
linkNodeName, linkAttrName = link.split('.')
334334
try:
335-
g.addEdge(g.node(linkNode).attribute(linkAttr), self)
335+
node = g.node(linkNodeName)
336+
if not node:
337+
raise KeyError(f"Node '{linkNodeName}' not found")
338+
g.addEdge(node.attribute(linkAttrName), self)
336339
except KeyError as err:
337340
logging.warning('Connect Attribute from Expression failed.')
338341
logging.warning('Expression: "{exp}"\nError: "{err}".'.format(exp=v, err=err))

tests/test_graphIO.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,15 @@ def test_nodeWithoutVersionInfoIsUpgraded(self):
336336
assert len(graph.nodes) == 1
337337
assert len(graph.compatibilityNodes) == 0
338338

339+
def test_connectionsToMissingNodesAreDiscarded(self):
340+
graph = Graph("")
341+
342+
with registeredNodeTypes([SimpleNode]):
343+
sampleGraphContent = dedent("""
344+
{
345+
"SimpleNode_1": {
346+
"nodeType": "SimpleNode", "inputs": { "input": "{NotSerializedNode.output}" }
347+
}
348+
}
349+
""")
350+
graph._deserialize(json.loads(sampleGraphContent))

0 commit comments

Comments
 (0)