Skip to content

fix(connections): tolerate list body when retrieving a single connection (PC-4777)#1759

Open
cotovanu-cristian wants to merge 1 commit into
mainfrom
fix/pc-4777-connections-list-parse
Open

fix(connections): tolerate list body when retrieving a single connection (PC-4777)#1759
cotovanu-cristian wants to merge 1 commit into
mainfrom
fix/pc-4777-connections-list-parse

Conversation

@cotovanu-cristian

@cotovanu-cristian cotovanu-cristian commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

ConnectionsService.retrieve / retrieve_async validated the connections_/api/v1/Connections response against the single Connection Pydantic model. When the endpoint answers with a list, Connection.model_validate(response.json()) raised:

pydantic_core.ValidationError: 1 validation error for Connection
  Input should be a valid dictionary or instance of Connection [type=model_type, input_type=list]

In production this surfaced as a generic AgentRuntimeError (miscategorized Unknown) during tool connection resolution: integration_tool -> invoke_activity_async -> retrieve_async -> Connection.model_validate(<list>).

  • Jira: PC-4777
  • Incident: SRE-610701, job 2d3bb528-02b9-402a-96cf-52203b64de4b

Root cause

Pinned from the incident traceback to _connections_service.py retrieve_async (and symmetrically retrieve): the response body was a list, but the code validated it as one Connection. 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 both retrieve and retrieve_async:

  • single object -> existing behavior (Connection.model_validate)
  • list -> select the connection whose id matches the requested key, falling back to the first entry; raise ValueError for an empty list

Method signatures and single-object behavior are unchanged.

Tests

Added to tests/services/test_connections_service.py:

  • test_retrieve_selects_matching_connection_from_list_response
  • test_retrieve_async_selects_matching_connection_from_list_response
  • test_retrieve_falls_back_to_first_connection_when_no_key_match

The first two reproduce the exact PC-4777 ValidationError before the fix (red), and pass after.

Validation

  • uv run ruff check — pass
  • uv run ruff format --check — pass
  • uv run mypy src/uipath/platform/connections/_connections_service.py — pass
  • uv run pytest tests/services/test_connections_service.py — 63 passed

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 24, 2026 16:35
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels Jun 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 matching id (or falling back to the first element) and validating as a Connection.
  • Updated both retrieve and retrieve_async to use _select_connection instead 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.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
88.9% Coverage on New Code (required ≥ 90%)

See analysis details on SonarQube Cloud

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

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants