Skip to content

Commit eb55d13

Browse files
Handle bad response on multipart bundle upload (#814)
The multipart form path in upload_bundle (used when metadata is provided) never called handle_bad_response, so a bad HTTP response propagated as a raw HTTPResponse and caused cryptic downstream failures. Call it for both upload paths. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0dbd416 commit eb55d13

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

rsconnect/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def upload_bundle(
736736
response = cast(
737737
Union[BundleMetadata, HTTPResponse], self.post(f"v1/content/{content_guid}/bundles", body=tarball)
738738
)
739-
response = self._server.handle_bad_response(response)
739+
response = self._server.handle_bad_response(response)
740740
return response
741741

742742
def content_update(self, content_guid: str, updates: Mapping[str, str | None]) -> ContentItemV1:

tests/test_git_metadata.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,22 @@ def test_upload_bundle_signature_accepts_metadata(self):
266266
# Check that upload_bundle has metadata parameter
267267
sig = signature(RSConnectClient.upload_bundle)
268268
assert "metadata" in sig.parameters
269+
270+
def test_upload_bundle_with_metadata_handles_bad_response(self):
271+
"""A bad response on the multipart (metadata) upload path is surfaced as an
272+
RSConnectException rather than a raw HTTPResponse (issue #814)."""
273+
import io
274+
from unittest.mock import patch
275+
276+
from rsconnect.api import RSConnectClient, RSConnectException, RSConnectServer
277+
from rsconnect.http_support import HTTPResponse
278+
279+
client = RSConnectClient(RSConnectServer("http://test-server", "api_key"))
280+
bad_response = HTTPResponse(
281+
"http://test-server/__api__/v1/content/guid/bundles",
282+
exception=OSError("connection refused"),
283+
)
284+
with patch.object(RSConnectClient, "post", return_value=bad_response):
285+
with pytest.raises(RSConnectException) as cm:
286+
client.upload_bundle("guid", io.BytesIO(b"tarball"), metadata={"source": "git"})
287+
assert "connection refused" in str(cm.value)

0 commit comments

Comments
 (0)