diff --git a/CHANGELOG.md b/CHANGELOG.md index fbfb17f4..6e0b8e1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ nylas-python Changelog Unreleased ---------------- +* Fix error when trying to iterate on list after calling count +* Fix error when setting participant status on create event + +v5.14.0 +---------------- * Add support for verifying webhook signatures * Add optional parameter for token-info endpoint diff --git a/nylas/client/restful_models.py b/nylas/client/restful_models.py index 69d95d96..b6539e78 100644 --- a/nylas/client/restful_models.py +++ b/nylas/client/restful_models.py @@ -726,7 +726,11 @@ def as_json(self, enforce_read_only=True): dct["when"] = dct["when"].copy() dct["when"].pop("object", None) - if dct.get("participants") and isinstance(dct.get("participants"), list): + if ( + dct.get("participants") + and isinstance(dct.get("participants"), list) + and self.id + ): # The status of a participant cannot be updated and, if the key is # included, it will return an error from the API for participant in dct.get("participants"): diff --git a/tests/test_events.py b/tests/test_events.py index 6c347db9..068ba995 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -26,11 +26,15 @@ def test_event_crud(mocked_responses, api_client): event1.master_event_id = "should not send" event1.original_start_time = "should not send" event1.visibility = "private" + event1.participants = [ + {"email": "person1@email.com", "status": "yes"}, + ] event1.save() request = mocked_responses.calls[0].request body = json.loads(request.body) assert event1.id == "cv4ei7syx10uvsxbs21ccsezf" - assert event1.visibility == "private" + assert body["participants"][0]["status"] == "yes" + assert body["visibility"] == "private" assert "title" in body assert "object" not in body assert "account_id" not in body @@ -43,9 +47,13 @@ def test_event_crud(mocked_responses, api_client): assert "original_start_time" not in body event1.title = "blah" + assert "participants" in event1 + event1["participants"][0]["status"] = "no" event1.save() request = mocked_responses.calls[1].request body = json.loads(request.body) + assert body["title"] == "blah" + assert "status" not in body["participants"][0] assert event1.title == "loaded from JSON" assert event1.get("ignored") is None assert "id" not in body