Skip to content

Commit

Permalink
[core] Check existence of group or list attributes correctly
Browse files Browse the repository at this point in the history
"hasAttribute" was previously never called before attempting to
access an attribute. With the addition of internal attributes, we
want to check the attribute's/internal attribute's before accessing
it to avoid KeyError exceptions. "hasAttribute" (and the newly added
"hasInternalAttribute") would not parse the attribute's name before
checking for its existence, meaning that errors could be generated for
list or group attributes as their checked name could contain other
elements (e.g. "featuresFolder[0]" for a ListAttribute named
"featuresFolder").
  • Loading branch information
cbentejac committed Oct 13, 2022
1 parent 5399c4d commit 5cee129
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,18 @@ def getInternalAttributes(self):

@Slot(str, result=bool)
def hasAttribute(self, name):
# Complex name indicating group or list attribute: parse it and get the
# first output element to check for the attribute's existence
if "[" in name or "." in name:
p = self.attributeRE.findall(name)
return p[0][0] in self._attributes.keys() or p[0][1] in self._attributes.keys()
return name in self._attributes.keys()

@Slot(str, result=bool)
def hasInternalAttribute(self, name):
if "[" in name or "." in name:
p = self.attributeRE.findall(name)
return p[0][0] in self._internalAttributes.keys() or p[0][1] in self._internalAttributes.keys()
return name in self._internalAttributes.keys()

def _applyExpr(self):
Expand Down

0 comments on commit 5cee129

Please sign in to comment.