Skip to content

Fix CLI document add command: send form data instead of URL parameters#152

Closed
Copilot wants to merge 5 commits intodevelopfrom
copilot/fix-0444966e-7d27-45c8-a526-a2454c93cd14
Closed

Fix CLI document add command: send form data instead of URL parameters#152
Copilot wants to merge 5 commits intodevelopfrom
copilot/fix-0444966e-7d27-45c8-a526-a2454c93cd14

Conversation

Copy link
Contributor

Copilot AI commented Sep 6, 2025

Problem

The CLI command extralit documents add --workspace <workspace> --reference <ref> --file <file> was failing with the error "Server disconnected without sending a response." This prevented users from adding individual documents via the CLI.

Root Cause

The issue was a mismatch between how the client sends document metadata and how the server expects to receive it:

  • Client: The DocumentsAPI.create() method was sending document metadata as URL parameters (params=document_payload)
  • Server: The /api/v1/documents endpoint expects document metadata as form fields via FastAPI's Depends() mechanism

When uploading files with multipart form data, this parameter/form data mismatch caused the server to fail parsing the request, resulting in a dropped connection.

Solution

Modified DocumentsAPI.create() in extralit/src/extralit/_api/_documents.py to send document metadata in the correct format:

  • File uploads: Send metadata as form data (data=document_payload) with multipart files - compatible with FastAPI Depends()
  • Non-file uploads: Send metadata as JSON (json=document_payload) - also compatible with FastAPI
  • Removed: URL parameters (params=document_payload) which were incompatible
# Before (broken)
response = self.http_client.post(url=url, params=document_payload, files=files)

# After (fixed) 
response = self.http_client.post(url=url, data=document_payload, files=files)

Testing

Verified the fix works correctly for both scenarios:

  • ✅ File uploads now send metadata as form fields with multipart files
  • ✅ URL-only documents send metadata as JSON
  • ✅ No URL parameters are used (which were causing the compatibility issue)

The CLI command extralit documents add --workspace priyankesh-test --reference paper-001 --file ./paper.pdf should now work as expected.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 6, 2025 22:22
…match

Co-authored-by: dawn-tran <104935595+dawn-tran@users.noreply.github.com>
… params

Co-authored-by: dawn-tran <104935595+dawn-tran@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue where the CLI extralit documents add --workspace priyankesh-test --reference paper-001 --file .\paper.pdf no longer works (resulting in error Error adding document: Server disconnected without sending a response.) because the add_document... Fix CLI document add command: send form data instead of URL parameters Sep 6, 2025
Copilot AI requested a review from dawn-tran September 6, 2025 22:27
@JonnyTran JonnyTran closed this Sep 8, 2025
@JonnyTran JonnyTran deleted the copilot/fix-0444966e-7d27-45c8-a526-a2454c93cd14 branch September 8, 2025 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants