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": "test@example.com"}],
"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
- 平均マージ
- 1日 21時間
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nylas/nylas-python のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 48/100
nylas/nylas-python#455 ·
-
bug
nylas/nylas-python#448 · コメント 1 件 · 担当者 2 名 ·
-
enhancement
nylas/nylas-python#412 · コメント 1 件 · リアクション 5 件 · 担当者 1 名 ·
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
nylas/nylas-python#402 · リアクション 1 件 ·
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
nylas/nylas-python#401 ·
nylas/nylas-python の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
zostera/django-bootstrap4#894 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
use-agent-os/agent-os#3276 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#117848 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
zilliztech/memsearch#759 ·