Skip to content

Commit

Permalink
[iot] update_thing(): empty attributes are deleted with merge=true (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Wurstnase authored Oct 13, 2023
1 parent f59e178 commit 44fe39f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions moto/iot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def update_thing(
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
Expand Down Expand Up @@ -1307,7 +1307,6 @@ def list_principal_things(self, principal_arn: str) -> List[str]:
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(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_iot/test_iot_things.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 44fe39f

Please sign in to comment.