Skip to content

Commit 857b7ea

Browse files
committed
Update to reflect expected behavior
1 parent f561efe commit 857b7ea

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

pymongo/pool_options.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -179,39 +179,37 @@ def _getenv_int(key: str) -> Optional[int]:
179179
def _metadata_env() -> dict[str, Any]:
180180
env: dict[str, Any] = {}
181181
container = get_container_env_info()
182-
# Don't populate FaaS metadata if a container is present.
183182
if container:
184183
env["container"] = container
185-
else:
186-
# Skip if multiple (or no) envs are matched.
187-
if (_is_lambda(), _is_azure_func(), _is_gcp_func(), _is_vercel()).count(True) != 1:
188-
return env
189-
if _is_lambda():
190-
env["name"] = "aws.lambda"
191-
region = os.getenv("AWS_REGION")
192-
if region:
193-
env["region"] = region
194-
memory_mb = _getenv_int("AWS_LAMBDA_FUNCTION_MEMORY_SIZE")
195-
if memory_mb is not None:
196-
env["memory_mb"] = memory_mb
197-
elif _is_azure_func():
198-
env["name"] = "azure.func"
199-
elif _is_gcp_func():
200-
env["name"] = "gcp.func"
201-
region = os.getenv("FUNCTION_REGION")
202-
if region:
203-
env["region"] = region
204-
memory_mb = _getenv_int("FUNCTION_MEMORY_MB")
205-
if memory_mb is not None:
206-
env["memory_mb"] = memory_mb
207-
timeout_sec = _getenv_int("FUNCTION_TIMEOUT_SEC")
208-
if timeout_sec is not None:
209-
env["timeout_sec"] = timeout_sec
210-
elif _is_vercel():
211-
env["name"] = "vercel"
212-
region = os.getenv("VERCEL_REGION")
213-
if region:
214-
env["region"] = region
184+
# Skip if multiple (or no) envs are matched.
185+
if (_is_lambda(), _is_azure_func(), _is_gcp_func(), _is_vercel()).count(True) != 1:
186+
return env
187+
if _is_lambda():
188+
env["name"] = "aws.lambda"
189+
region = os.getenv("AWS_REGION")
190+
if region:
191+
env["region"] = region
192+
memory_mb = _getenv_int("AWS_LAMBDA_FUNCTION_MEMORY_SIZE")
193+
if memory_mb is not None:
194+
env["memory_mb"] = memory_mb
195+
elif _is_azure_func():
196+
env["name"] = "azure.func"
197+
elif _is_gcp_func():
198+
env["name"] = "gcp.func"
199+
region = os.getenv("FUNCTION_REGION")
200+
if region:
201+
env["region"] = region
202+
memory_mb = _getenv_int("FUNCTION_MEMORY_MB")
203+
if memory_mb is not None:
204+
env["memory_mb"] = memory_mb
205+
timeout_sec = _getenv_int("FUNCTION_TIMEOUT_SEC")
206+
if timeout_sec is not None:
207+
env["timeout_sec"] = timeout_sec
208+
elif _is_vercel():
209+
env["name"] = "vercel"
210+
region = os.getenv("VERCEL_REGION")
211+
if region:
212+
env["region"] = region
215213
return env
216214

217215

test/asynchronous/test_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,15 +2020,19 @@ async def test_handshake_08_invalid_aws_ec2(self):
20202020
)
20212021

20222022
async def test_handshake_09_container_with_provider(self):
2023-
# No FaaS metadata should be present.
20242023
await self._test_handshake(
20252024
{
20262025
ENV_VAR_K8S: "1",
20272026
"AWS_LAMBDA_RUNTIME_API": "1",
20282027
"AWS_REGION": "us-east-1",
20292028
"AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "256",
20302029
},
2031-
{"container": {"orchestrator": "kubernetes"}},
2030+
{
2031+
"container": {"orchestrator": "kubernetes"},
2032+
"name": "aws.lambda",
2033+
"region": "us-east-1",
2034+
"memory_mb": 256,
2035+
},
20322036
)
20332037

20342038
def test_dict_hints(self):

test/test_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,15 +1978,19 @@ def test_handshake_08_invalid_aws_ec2(self):
19781978
)
19791979

19801980
def test_handshake_09_container_with_provider(self):
1981-
# No FaaS metadata should be present.
19821981
self._test_handshake(
19831982
{
19841983
ENV_VAR_K8S: "1",
19851984
"AWS_LAMBDA_RUNTIME_API": "1",
19861985
"AWS_REGION": "us-east-1",
19871986
"AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "256",
19881987
},
1989-
{"container": {"orchestrator": "kubernetes"}},
1988+
{
1989+
"container": {"orchestrator": "kubernetes"},
1990+
"name": "aws.lambda",
1991+
"region": "us-east-1",
1992+
"memory_mb": 256,
1993+
},
19901994
)
19911995

19921996
def test_dict_hints(self):

0 commit comments

Comments
 (0)