Skip to content

fix: avoid writing None AWS region to environment#783

Open
euisuh wants to merge 1 commit into
cohere-ai:mainfrom
euisuh:fix/aws-client-none-region-env
Open

fix: avoid writing None AWS region to environment#783
euisuh wants to merge 1 commit into
cohere-ai:mainfrom
euisuh:fix/aws-client-none-region-env

Conversation

@euisuh

@euisuh euisuh commented Jul 24, 2026

Copy link
Copy Markdown

Summary

Fix the manually maintained AWS client so constructing cohere.manually_maintained.cohere_aws.client.Client() without an explicit aws_region no longer writes None into AWS_DEFAULT_REGION.

When both aws_region and AWS_DEFAULT_REGION were unset, the client attempted:

os.environ["AWS_DEFAULT_REGION"] = None

which raises TypeError: str expected, not NoneType before boto3 can resolve its normal region provider chain. This change only writes the environment variable when aws_region is provided.

Test Plan

  • pytest -q tests/test_aws_client_unit.py
  • pytest -q tests/test_aws_client_unit.py tests/test_embed_utils.py tests/test_embed_streaming.py
  • ruff check src/cohere/manually_maintained/cohere_aws/client.py tests/test_aws_client_unit.py
  • git diff --check

Note

Low Risk
Narrow init guard around environment mutation; behavior unchanged when an explicit region is passed.

Overview
Fixes a crash when constructing cohere.manually_maintained.cohere_aws.client.Client() without aws_region and with AWS_DEFAULT_REGION unset. The client previously always assigned os.environ['AWS_DEFAULT_REGION'] = aws_region, which raised TypeError when aws_region was None. It now only sets that env var when aws_region is provided, so boto3 can use its normal region resolution chain.

Adds a unit test that clears the environment, constructs Client() with no region, and asserts AWS_DEFAULT_REGION is not set while boto3 still receives region_name=None.

Reviewed by Cursor Bugbot for commit 4bfbf17. Bugbot is set up for automated code reviews on this repo. Configure here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant