Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unable to set participant status on create event #264

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion nylas/client/restful_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
10 changes: 9 additions & 1 deletion tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down