Skip to content

Python: fix(bedrock): resolve the BedrockEmbeddingClient region like the chat client - #9349

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
shanto462:fix-bedrock-embedding-region
Oct 16, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
shanto462:fix-bedrock-embedding-region

Conversation

@shanto462

Copy link
Copy Markdown
Contributor

Motivation & Context

BedrockEmbeddingClient built its runtime client with region_name=boto3_session.region_name or resolved_region, so a provided session's region won over an explicit region or BEDROCK_REGION. Its region attribute was always the configured region or us-east-1, even when requests went to the session's region or to the region boto3 resolved from its own configuration. BedrockChatClient already resolves the region in the expected order (#9249).

Description & Review Guide

  • What are the major changes? The embedding client now resolves the region as region / BEDROCK_REGION, then the session's region (or boto3's own configuration when no session is passed, as before), then us-east-1, and uses that same value for the runtime client and for client.region. Both region docstrings describe this order. Regression tests mirror the chat client's from Python: fix(bedrock): use the boto3 session's region in BedrockChatClient #9249: a parametrized session test (session region, region argument wins, BEDROCK_REGION wins, default), a test that boto3's default region is reported, and a test that a pre-built client still ignores the session.
  • What is the impact of these changes? A client created with an explicit region and a session in another region now sends requests to the explicit region, like the chat client; passing no region keeps the session's region. client.region now matches the region in use. Nothing changes when a pre-built client is passed, and credentials handling is unchanged.
  • What do you want reviewers to focus on? Without a session, the embedding client still lets boto3 resolve the region from its own configuration (environment, config file), as its docstring has always said. The chat client pins us-east-1 in that case; I left that difference alone so this PR does not change the no-session behavior of either client.

Related Issue

Fixes #9348

No other open PR covers this issue.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: issue analysis, implementation, tests, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

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.

🟢 Approval recommended

The implementation matches the documented behavior and includes focused regression coverage.

0 open findings

What changed in this PR

Aligns Bedrock embedding region resolution with the intended precedence while preserving boto3 defaults.

Changes:

  • Prioritizes configured regions over session regions.
  • Keeps client.region consistent with the runtime region.
  • Adds regression coverage and updates docstrings.
File Description
_embedding_client.py Corrects region resolution and documentation.
test_bedrock_embedding_client.py Tests region precedence, boto3 defaults, and prebuilt clients.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Merged via the queue into microsoft:main with commit 074e112 Oct 16, 2026
49 of 50 checks passed
@shanto462
Md. Shalah Uddin (shanto462) deleted the fix-bedrock-embedding-region branch October 19, 2026 09:42

This branch was successfully deployed

1 active deployment
github-app-auth — 45420b3c Deployed Oct 13, 2026 by shanto462 via team_check #6707
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: BedrockEmbeddingClient ignores an explicit region when a boto3_session is passed, and reports the wrong region

3 participants