Bug: drafts.create() fails with TypeError for multipart requests (attachments > 3MB)
評估
這個 Issue 還沒有評估資料。
描述
Bug Description
When creating a draft with attachments larger than 3MB (which triggers multipart upload), the SDK throws a TypeError: tuple indices must be integers or slices, not str.
Root Cause
In nylas/resources/drafts.py, the create() method (lines 117-124) doesn't properly unpack the tuple returned by _execute():
# Current buggy code (line 117-124):
if attachment_size >= MAXIMUM_JSON_ATTACHMENT_SIZE:
json_response = self._http_client._execute( # Returns (json_response, headers) tuple!
method="POST",
path=path,
data=_build_form_request(request_body),
overrides=overrides,
)
return Response.from_dict(json_response, Draft) # Fails - json_response is a tuple
Compare with the correct implementation in send() method (lines 222-228):
# Correct code in send():
json_response, headers = self._http_client._execute( # Properly unpacks tuple
method="POST",
path=f"/v3/grants/{identifier}/drafts/{urllib.parse.quote(draft_id, safe='')}",
overrides=overrides,
)
return Response.from_dict(json_response, Message, headers) # Works correctly
Steps to Reproduce
import os
import tempfile
from nylas import Client
from nylas.utils.file_utils import attach_file_request_builder
client = Client(api_key="your_api_key", api_uri="https://api.us.nylas.com")
# Create a temp file > 3MB to trigger multipart
with tempfile.NamedTemporaryFile(delete=False, suffix=".bin") as f:
f.write(b"x" * (4 * 1024 * 1024)) # 4MB file
temp_path = f.name
try:
attachment = attach_file_request_builder(temp_path)
response = client.drafts.create(
identifier="your_grant_id",
request_body={
"to": [{"email": "[email protected]"}],
"subject": "Test with large attachment",
"body": "Testing multipart upload",
"attachments": [attachment],
}
)
except TypeError as e:
print(f"Error: {e}") # "tuple indices must be integers or slices, not str"
finally:
os.remove(temp_path)
Expected Behavior
Draft should be created successfully and return a Response[Draft] object.
Actual Behavior
Throws TypeError: tuple indices must be integers or slices, not str
Suggested Fix
# In nylas/resources/drafts.py, change lines 117-124 to:
if attachment_size >= MAXIMUM_JSON_ATTACHMENT_SIZE:
json_response, headers = self._http_client._execute( # Unpack tuple
method="POST",
path=path,
data=_build_form_request(request_body),
overrides=overrides,
)
return Response.from_dict(json_response, Draft, headers) # Pass headers
Environment
- nylas-python version: 6.x (tested on latest)
- Python version: 3.12
- 主要語言
- Python
- 星號
- 109
- 分支
- 85
- 平均合併
- 8 小時 41 分鐘
- 30 天內合併 PR
- 3
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nylas/nylas-python 的其他 Issue
-
Attachment downloads ignore request URL and header overrides可能已有人在做 @Kayvan-Zahiri 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 39/100
nylas/nylas-python#491 ·
-
bug
難度 2/5 1-3 小時 新手友好度 48/100
nylas/nylas-python#455 ·
-
UnicodeEncodeError when sending e-mails with some iso-8859 characters (€ symbol)可能重新可做 @pengfeiye 於 278 天前認領,目前沒有進行中的 PR。 未關閉bug
nylas/nylas-python#448 · 1 則留言 · 已指派 2 人 ·
-
Create an async version of the client可能重新可做 @AaronDDM 於 496 天前認領,目前沒有進行中的 PR。 未關閉enhancement
nylas/nylas-python#412 · 1 則留言 · 5 個 reaction · 已指派 1 人 ·
-
bug
難度 3/5 1-2 天 新手友好度 38/100
nylas/nylas-python#402 · 1 個 reaction ·
查看 nylas/nylas-python 的全部 Issue
相似的 Issue
-
[Bug] Unit tests reach real Bedrock call paths without patching the model可能已有人在做 @proton0210 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 67/100
aws-samples/sample-aws-genai-db-modernizer#1318 · 1 則留言 ·
維護者通常 1 天內回覆
-
pyarrow-25.0.1-cp310-cp310-manylinux_2_28_x86_64.whl: 1 vulnerabilities (highest severity is: 5.3)未關閉Mend: dependency security vulnerability
難度 2/5 1-3 小時 新手友好度 62/100
capitalone/locopy#394 ·
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
sdk-typescript: unquoted COPY globs in shell form are silently dropped from the image build context未關閉bug javascript
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
enhancement
難度 2/5 1-3 小時 新手友好度 65/100
ietf-tools/datatracker#11922 · 1 則留言 ·
維護者通常 1 天內回覆