Bug: drafts.create() fails with TypeError for multipart requests (attachments > 3MB)
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 109
- Fork
- 85
- Merge trung bình
- 8 giờ 41 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nylas/nylas-python
-
Attachment downloads ignore request URL and header overridesCó thể đã có người làm @Kayvan-Zahiri đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 39/100
nylas/nylas-python#491 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 48/100
nylas/nylas-python#455 ·
-
UnicodeEncodeError when sending e-mails with some iso-8859 characters (€ symbol)Có thể làm lại được @pengfeiye đã nhận 277 ngày trước và không có pull request nào đang mở. Đang mởbug
nylas/nylas-python#448 · 1 bình luận · 2 người được giao ·
-
Create an async version of the clientCó thể làm lại được @AaronDDM đã nhận 495 ngày trước và không có pull request nào đang mở. Đang mởenhancement
nylas/nylas-python#412 · 1 bình luận · 5 reaction · 1 người được giao ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
nylas/nylas-python#402 · 1 reaction ·
Tất cả issue của nylas/nylas-python
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mohitmishra786/readprism#322 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
API-key credentials accept a blank key: empty via the API, spaces-only via the builder's Add API key dialogCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Significant-Gravitas/AutoGPT#15727 ·
Maintainer thường phản hồi trong vòng 1 ngày