Fix dictionary changed size during iteration error in override_provider_tokens_with_custom_secret (#9728)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Graham Neubig
2025-07-15 19:03:28 -04:00
committed by GitHub
parent 1d95b01514
commit 4c10848e8d
2 changed files with 53 additions and 6 deletions

View File

@@ -290,12 +290,16 @@ class AgentSession:
custom_secrets: CUSTOM_SECRETS_TYPE | None,
):
if git_provider_tokens and custom_secrets:
tokens = dict(git_provider_tokens)
for provider, _ in tokens.items():
token_name = ProviderHandler.get_provider_env_key(provider)
if token_name in custom_secrets or token_name.upper() in custom_secrets:
del tokens[provider]
# Use dictionary comprehension to avoid modifying dictionary during iteration
tokens = {
provider: token
for provider, token in git_provider_tokens.items()
if not (
ProviderHandler.get_provider_env_key(provider) in custom_secrets
or ProviderHandler.get_provider_env_key(provider).upper()
in custom_secrets
)
}
return MappingProxyType(tokens)
return git_provider_tokens