fix: httpx 0.28 AsyncClient multipart compat — pass all fields via files= list
All checks were successful
Deploy / deploy (push) Successful in 15s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-22 20:01:28 +01:00
parent 26a00d3e26
commit c87bc6a954

View File

@@ -116,23 +116,26 @@ class PaperlessClient:
self, file_bytes: bytes, filename: str, metadata: dict self, file_bytes: bytes, filename: str, metadata: dict
) -> str: ) -> str:
"""Upload a document; returns the Celery task_id UUID string.""" """Upload a document; returns the Celery task_id UUID string."""
form: list[tuple[str, str]] = [] # Build multipart as a list of tuples so all parts go through a single
# AsyncByteStream — required for httpx >= 0.28 with AsyncClient.
parts: list[tuple[str, tuple]] = [
("document", (filename, file_bytes, "application/octet-stream")),
]
for key in ("title", "created", "archive_serial_number"): for key in ("title", "created", "archive_serial_number"):
val = metadata.get(key) val = metadata.get(key)
if val is not None: if val is not None:
form.append((key, str(val))) parts.append((key, (None, str(val), "text/plain")))
if metadata.get("correspondent") is not None: if metadata.get("correspondent") is not None:
form.append(("correspondent", str(metadata["correspondent"]))) parts.append(("correspondent", (None, str(metadata["correspondent"]), "text/plain")))
if metadata.get("document_type") is not None: if metadata.get("document_type") is not None:
form.append(("document_type", str(metadata["document_type"]))) parts.append(("document_type", (None, str(metadata["document_type"]), "text/plain")))
for tag_id in metadata.get("tags", []): for tag_id in metadata.get("tags", []):
form.append(("tags", str(tag_id))) parts.append(("tags", (None, str(tag_id), "text/plain")))
r = await self._request( r = await self._request(
"POST", "POST",
"/api/documents/post_document/", "/api/documents/post_document/",
files={"document": (filename, file_bytes, "application/octet-stream")}, files=parts,
data=form,
) )
result = r.json() result = r.json()
# API returns a plain task UUID string # API returns a plain task UUID string