Skip to content

Fix Bulk API 2.0 job results returning None for CSV responses - #80

Open
jeromeyyy wants to merge 3 commits into
forcedotcom:masterfrom
jeromeyyy:fix/bulk-job-results-csv
Open

jeromeyyy wants to merge 3 commits into
forcedotcom:masterfrom
jeromeyyy:fix/bulk-job-results-csv

Conversation

@jeromeyyy

Copy link
Copy Markdown

Fixes #57.

BaseRequest.request in SalesforcePy/commons.py unconditionally parses every response body with response.json(). The Bulk API 2.0 job results endpoints (successfulResults, failedResults, unprocessedrecords) return text/csv, so the JSON parse raises, the exception is swallowed by the except/finally, and callers always get None. This matches the symptom reported in #57; I reproduced it locally with a mocked text/csv response (no live-org testing).

Change

Parse the response by its Content-Type:

  • empty body: return None (unchanged from current behavior, e.g. batch upload 201 responses)
  • CSV content type: return the body as text, consistent with the docs which state a CSV of records is returned for these endpoints
  • anything else: response.json() exactly as before, so no other endpoint or content type changes behavior

The binary/blob path is unaffected: SObjectBlob overrides request() and handles the streamed response itself.

Tests

The test harness in tests/testutil.py JSON-encoded string fixture bodies before serving them, so the mocked CSV endpoints were served as JSON string literals and the existing tests could not reproduce the real API behavior. The harness now serves string bodies verbatim. With that correction, the existing test_get_successful_jobs, test_get_failed_jobs and test_get_unprocessed_jobs fail against the original code (they return None) and pass with this fix. Two blob assertions in tests/test_sobjects.py that expected the double-encoded content were updated; they pass on both original and fixed code.

Full test suite: 79 passed.

Happy to adjust if you would prefer a different return type for the CSV endpoints.

@salesforce-cla

salesforce-cla Bot commented Nov 3, 2026

Copy link
Copy Markdown

Thanks for the contribution! Before we can merge this, we need @jeromeyyy to sign the Salesforce Inc. Contributor License Agreement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bulk API 2.0 always returns 'None' when getting Job successful/Failed/Unprocessed record results

1 participant