Skip to content

Commit

Permalink
Remove KeyError encountered on unknown attributes (#22600)
Browse files Browse the repository at this point in the history
This removes the KeyError exception that is thrown when the Python
cluster cache encounters an attribute that it doesn't have schema for.
This occurs for some of the extended attributes in the test cluster that
are not actually defined in schema.

This ensures that we don't abruptly terminate attribute processing when
running tests against the all clusters app.
  • Loading branch information
mrjerryjohns authored Sep 15, 2022
1 parent 283a40c commit c6cde56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
27 changes: 14 additions & 13 deletions src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,14 @@ def UpdateCachedData(self):
endpointCache = attributeCache[endpoint]

for cluster in tlvCache[endpoint]:
if cluster not in _ClusterIndex:
#
# #22599 tracks dealing with unknown clusters more
# gracefully so that clients can still access this data.
#
continue

clusterType = _ClusterIndex[cluster]
if (clusterType is None):
raise Exception("Cannot find cluster in cluster index")

if (clusterType not in endpointCache):
endpointCache[clusterType] = {}
Expand All @@ -427,9 +432,6 @@ def UpdateCachedData(self):
endpointCache[clusterType].SetDataVersion(
clusterDataVersion)
except Exception as ex:
logging.error(
f"Error converting TLV to Cluster Object for path: Endpoint = {endpoint}, cluster = {str(clusterType)}")
logging.error(f"|-- Exception: {repr(ex)}")
decodedValue = ValueDecodeFailure(
tlvCache[endpoint][cluster], ex)
endpointCache[clusterType] = decodedValue
Expand All @@ -438,27 +440,26 @@ def UpdateCachedData(self):
for attribute in tlvCache[endpoint][cluster]:
value = tlvCache[endpoint][cluster][attribute]

if (cluster, attribute) not in _AttributeIndex:
#
# #22599 tracks dealing with unknown clusters more
# gracefully so that clients can still access this data.
#
continue

attributeType = _AttributeIndex[(
cluster, attribute)][0]
if (attributeType is None):
raise Exception(
"Cannot find attribute in attribute index")

if (attributeType not in clusterCache):
clusterCache[attributeType] = {}

if (type(value) is ValueDecodeFailure):
logging.error(
f"For path: Endpoint = {endpoint}, Attribute = {str(attributeType)}, got IM Error: {str(value.Reason)}")
clusterCache[attributeType] = value
else:
try:
decodedValue = attributeType.FromTagDictOrRawValue(
tlvCache[endpoint][cluster][attribute])
except Exception as ex:
logging.error(
f"Error converting TLV to Cluster Object for path: Endpoint = {endpoint}, Attribute = {str(attributeType)}")
logging.error(f"|-- Exception: {repr(ex)}")
decodedValue = ValueDecodeFailure(value, ex)

clusterCache[attributeType] = decodedValue
Expand Down
5 changes: 1 addition & 4 deletions src/controller/python/chip/clusters/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ class ReadClientCallback : public ReadClient::Callback
{
version = aPath.mDataVersion.Value();
}
else
{
ChipLogError(DataManagement, "expect aPath has valid mDataVersion");
}

gOnReadAttributeDataCallback(mAppContext, version, aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId,
to_underlying(aStatus.mStatus), buffer.get(), size);
}
Expand Down

0 comments on commit c6cde56

Please sign in to comment.