diff --git a/moto/iot/models.py b/moto/iot/models.py index 14289a00d..1ebce5eaa 100644 --- a/moto/iot/models.py +++ b/moto/iot/models.py @@ -883,7 +883,7 @@ class IoTBackend(BaseBackend): if not do_merge: thing.attributes = attributes else: - thing.attributes.update(attributes) + thing.attributes = {k: v for k, v in attributes.items() if v} def create_keys_and_certificate( self, set_as_active: bool @@ -1307,7 +1307,6 @@ class IoTBackend(BaseBackend): return thing_names def list_thing_principals(self, thing_name: str) -> List[str]: - things = [_ for _ in self.things.values() if _.thing_name == thing_name] if len(things) == 0: raise ResourceNotFoundException( diff --git a/tests/test_iot/test_iot_things.py b/tests/test_iot/test_iot_things.py index 65f605ea5..773bdab3e 100644 --- a/tests/test_iot/test_iot_things.py +++ b/tests/test_iot/test_iot_things.py @@ -54,6 +54,15 @@ def test_update_thing(): assert res["things"][0]["thingArn"] is not None assert res["things"][0]["attributes"]["k1"] == "v1" + client.update_thing( + thingName=name, attributePayload={"attributes": {"k1": ""}, "merge": True} + ) + res = client.list_things() + assert len(res["things"]) == 1 + assert res["things"][0]["thingName"] is not None + assert res["things"][0]["thingArn"] is not None + assert res["things"][0]["attributes"] == {} + @mock_iot def test_describe_thing():