fix: avoid writing None AWS region to environment#783
Open
euisuh wants to merge 1 commit into
Open
Conversation
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
Fix the manually maintained AWS client so constructing
cohere.manually_maintained.cohere_aws.client.Client()without an explicitaws_regionno longer writesNoneintoAWS_DEFAULT_REGION.When both
aws_regionandAWS_DEFAULT_REGIONwere unset, the client attempted:which raises
TypeError: str expected, not NoneTypebefore boto3 can resolve its normal region provider chain. This change only writes the environment variable whenaws_regionis provided.Test Plan
pytest -q tests/test_aws_client_unit.pypytest -q tests/test_aws_client_unit.py tests/test_embed_utils.py tests/test_embed_streaming.pyruff check src/cohere/manually_maintained/cohere_aws/client.py tests/test_aws_client_unit.pygit diff --checkNote
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()withoutaws_regionand withAWS_DEFAULT_REGIONunset. The client previously always assignedos.environ['AWS_DEFAULT_REGION'] = aws_region, which raisedTypeErrorwhenaws_regionwasNone. It now only sets that env var whenaws_regionis provided, so boto3 can use its normal region resolution chain.Adds a unit test that clears the environment, constructs
Client()with no region, and assertsAWS_DEFAULT_REGIONis not set while boto3 still receivesregion_name=None.Reviewed by Cursor Bugbot for commit 4bfbf17. Bugbot is set up for automated code reviews on this repo. Configure here.