[iot] update_thing(): empty attributes are deleted with merge=true (#6910)

This commit is contained in:
Nico Tonnhofer 2023-10-13 21:09:30 +02:00 committed by GitHub
parent f59e178f27
commit 44fe39f584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -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(

View File

@ -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():