Skip to content

Commit 4406961

Browse files
mrjerryjohnspull[bot]
authored andcommitted
Remove KeyError encountered on unknown attributes (#22600)
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.
1 parent 434411c commit 4406961

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/controller/python/chip/clusters/Attribute.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,14 @@ def UpdateCachedData(self):
408408
endpointCache = attributeCache[endpoint]
409409

410410
for cluster in tlvCache[endpoint]:
411+
if cluster not in _ClusterIndex:
412+
#
413+
# #22599 tracks dealing with unknown clusters more
414+
# gracefully so that clients can still access this data.
415+
#
416+
continue
417+
411418
clusterType = _ClusterIndex[cluster]
412-
if (clusterType is None):
413-
raise Exception("Cannot find cluster in cluster index")
414419

415420
if (clusterType not in endpointCache):
416421
endpointCache[clusterType] = {}
@@ -427,9 +432,6 @@ def UpdateCachedData(self):
427432
endpointCache[clusterType].SetDataVersion(
428433
clusterDataVersion)
429434
except Exception as ex:
430-
logging.error(
431-
f"Error converting TLV to Cluster Object for path: Endpoint = {endpoint}, cluster = {str(clusterType)}")
432-
logging.error(f"|-- Exception: {repr(ex)}")
433435
decodedValue = ValueDecodeFailure(
434436
tlvCache[endpoint][cluster], ex)
435437
endpointCache[clusterType] = decodedValue
@@ -438,27 +440,26 @@ def UpdateCachedData(self):
438440
for attribute in tlvCache[endpoint][cluster]:
439441
value = tlvCache[endpoint][cluster][attribute]
440442

443+
if (cluster, attribute) not in _AttributeIndex:
444+
#
445+
# #22599 tracks dealing with unknown clusters more
446+
# gracefully so that clients can still access this data.
447+
#
448+
continue
449+
441450
attributeType = _AttributeIndex[(
442451
cluster, attribute)][0]
443-
if (attributeType is None):
444-
raise Exception(
445-
"Cannot find attribute in attribute index")
446452

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

450456
if (type(value) is ValueDecodeFailure):
451-
logging.error(
452-
f"For path: Endpoint = {endpoint}, Attribute = {str(attributeType)}, got IM Error: {str(value.Reason)}")
453457
clusterCache[attributeType] = value
454458
else:
455459
try:
456460
decodedValue = attributeType.FromTagDictOrRawValue(
457461
tlvCache[endpoint][cluster][attribute])
458462
except Exception as ex:
459-
logging.error(
460-
f"Error converting TLV to Cluster Object for path: Endpoint = {endpoint}, Attribute = {str(attributeType)}")
461-
logging.error(f"|-- Exception: {repr(ex)}")
462463
decodedValue = ValueDecodeFailure(value, ex)
463464

464465
clusterCache[attributeType] = decodedValue

src/controller/python/chip/clusters/attribute.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ class ReadClientCallback : public ReadClient::Callback
135135
{
136136
version = aPath.mDataVersion.Value();
137137
}
138-
else
139-
{
140-
ChipLogError(DataManagement, "expect aPath has valid mDataVersion");
141-
}
138+
142139
gOnReadAttributeDataCallback(mAppContext, version, aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId,
143140
to_underlying(aStatus.mStatus), buffer.get(), size);
144141
}

0 commit comments

Comments
 (0)