From 038ca895daaf17cb6712fb1dbd0a289753ed4574 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:11:40 +0000 Subject: [PATCH] fix: handle missing attributes when using select param - Add infer_missing=True to ListResponse.from_dict to handle missing attributes - Add test case to verify select parameter behavior - Fixes #395 Co-Authored-By: Aaron de Mello --- nylas/models/response.py | 2 +- tests/resources/test_threads.py | 44 ++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/nylas/models/response.py b/nylas/models/response.py index d00798c5..f8a91652 100644 --- a/nylas/models/response.py +++ b/nylas/models/response.py @@ -94,7 +94,7 @@ def from_dict(cls, resp: dict, generic_type): converted_data = [] for item in resp["data"]: - converted_data.append(generic_type.from_dict(item)) + converted_data.append(generic_type.from_dict(item, infer_missing=True)) return cls( data=converted_data, diff --git a/tests/resources/test_threads.py b/tests/resources/test_threads.py index 47c9cbec..749c4b90 100644 --- a/tests/resources/test_threads.py +++ b/tests/resources/test_threads.py @@ -1,7 +1,7 @@ from nylas.models.attachments import Attachment from nylas.models.events import EmailName +from nylas.models.response import ListResponse from nylas.resources.threads import Threads - from nylas.models.threads import Thread @@ -147,6 +147,48 @@ def test_list_threads_with_query_params(self, http_client_list_response): overrides=None, ) + def test_list_threads_with_select_param(self, http_client_list_response): + threads = Threads(http_client_list_response) + + # Set up mock response data + http_client_list_response._execute.return_value = { + "request_id": "abc-123", + "data": [{ + "id": "thread-123", + "has_attachments": False, + "earliest_message_date": 1634149514, + "participants": [ + {"email": "test@example.com", "name": "Test User"} + ], + "snippet": "Test snippet", + "unread": False, + "subject": "Test subject", + "message_ids": ["msg-123"], + "folders": ["folder-123"] + }] + } + + # Call the API method + result = threads.list( + identifier="abc-123", + query_params={ + "select": "id,has_attachments,earliest_message_date,participants,snippet,unread,subject,message_ids,folders" + } + ) + + # Verify API call + http_client_list_response._execute.assert_called_with( + "GET", + "/v3/grants/abc-123/threads", + None, + {"select": "id,has_attachments,earliest_message_date,participants,snippet,unread,subject,message_ids,folders"}, + None, + overrides=None, + ) + + # The actual response validation is handled by the mock in conftest.py + assert result is not None + def test_find_thread(self, http_client_response): threads = Threads(http_client_response)