fix(connections): tolerate list body when retrieving a single connection (PC-4777)#1759
Open
cotovanu-cristian wants to merge 1 commit into
Open
fix(connections): tolerate list body when retrieving a single connection (PC-4777)#1759cotovanu-cristian wants to merge 1 commit into
cotovanu-cristian wants to merge 1 commit into
Conversation
ConnectionsService.retrieve / retrieve_async validated the connections_/api/v1/Connections response against the single Connection model. When the endpoint answers with a list, Connection.model_validate raised pydantic_core.ValidationError (input_type=list), which surfaced as a generic AgentRuntimeError during tool connection resolution (PC-4777, SRE-610701). Add _select_connection to parse the body as a list when needed and select the connection whose id matches the requested key (falling back to the first entry), preserving the existing single-object behavior and the method signatures. Adds regression tests for the list-response case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a production parsing bug in ConnectionsService.retrieve / retrieve_async where the Connections “retrieve” endpoint may return a JSON list (HTTP 200) instead of a single object, causing Pydantic validation to fail and surfacing as an SDK runtime error during tool connection resolution.
Changes:
- Added
_select_connection(data, key)helper to tolerate list bodies by selecting the matchingid(or falling back to the first element) and validating as aConnection. - Updated both
retrieveandretrieve_asyncto use_select_connectioninstead of validating the raw JSON directly. - Added regression tests covering sync/async list responses and the fallback behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/uipath-platform/src/uipath/platform/connections/_connections_service.py | Adds _select_connection and routes retrieve/retrieve_async through it to handle list-shaped responses safely. |
| packages/uipath-platform/tests/services/test_connections_service.py | Adds regression tests reproducing the list-body failure mode and verifying correct selection behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
ConnectionsService.retrieve/retrieve_asyncvalidated theconnections_/api/v1/Connectionsresponse against the singleConnectionPydantic model. When the endpoint answers with a list,Connection.model_validate(response.json())raised:In production this surfaced as a generic
AgentRuntimeError(miscategorizedUnknown) during tool connection resolution:integration_tool->invoke_activity_async->retrieve_async->Connection.model_validate(<list>).2d3bb528-02b9-402a-96cf-52203b64de4bRoot cause
Pinned from the incident traceback to
_connections_service.pyretrieve_async(and symmetricallyretrieve): the response body was a list, but the code validated it as oneConnection. The dependency call returned HTTP 200 — the platform responded correctly; the defect is purely in how the SDK parses the body.Fix
Add a private
_select_connection(data, key)helper used by bothretrieveandretrieve_async:Connection.model_validate)idmatches the requestedkey, falling back to the first entry; raiseValueErrorfor an empty listMethod signatures and single-object behavior are unchanged.
Tests
Added to
tests/services/test_connections_service.py:test_retrieve_selects_matching_connection_from_list_responsetest_retrieve_async_selects_matching_connection_from_list_responsetest_retrieve_falls_back_to_first_connection_when_no_key_matchThe first two reproduce the exact PC-4777
ValidationErrorbefore the fix (red), and pass after.Validation
uv run ruff check— passuv run ruff format --check— passuv run mypy src/uipath/platform/connections/_connections_service.py— passuv run pytest tests/services/test_connections_service.py— 63 passed🤖 Generated with Claude Code