Description
In create_crew() (cli/create_crew.py), the for-loop on line 214 uses provider as its loop variable:
for provider, env_keys in ENV_VARS.items():
This shadows the provider parameter that's passed in from the CLI (crewai create crew <name> --provider <value>). After the loop finishes, provider no longer holds the user's original selection — it holds whatever the last key from ENV_VARS was (or the key where break was hit).
Currently the parameter isn't read again after the loop (the function uses selected_provider from interactive selection instead), so this doesn't cause a visible behavioral issue today. But it's a latent bug — anyone adding code after the loop that references provider would silently get the wrong value. It also trips static analysis warnings and makes debugging confusing.
Steps to Reproduce
- Read
create_crew() in lib/crewai/src/crewai/cli/create_crew.py
- Notice that line 214 uses
provider as the loop variable in for provider, env_keys in ENV_VARS.items()
- Add a
print(provider) after the loop (line 221) and call create_crew("test", provider="openai")
- Observe that
provider is no longer "openai"
Expected behavior
The provider parameter should retain its original value throughout the function. Loop variables should not shadow function parameters.
Screenshots/Code snippets
def create_crew(
name: str,
provider: str | None = None, # <-- parameter
skip_provider: bool = False,
parent_folder: str | None = None,
) -> None:
...
existing_provider = None
for provider, env_keys in ENV_VARS.items(): # <-- shadows parameter!
if any(
"key_name" in details and details["key_name"] in env_vars
for details in env_keys
):
existing_provider = provider
break
# At this point, `provider` is no longer the caller's value
Operating System
Ubuntu 22.04
Python Version
3.12
crewAI Version
1.13.0
crewAI Tools Version
1.13.0
Virtual Environment
Venv
Evidence
Standard Python scoping behavior — a for loop variable persists after the loop and overwrites any variable with the same name in the enclosing scope. Any linter (pylint W0621, ruff) would flag this as redefined-from-outer-scope.
Possible Solution
Rename the loop variable to env_provider (or similar) so the parameter isn't clobbered. I have a one-line fix ready and will open a PR.
Additional context
Side note: the --provider CLI flag doesn't seem to actually bypass the interactive provider selection — the function always calls select_provider() regardless. That's a separate issue though.
Description
In
create_crew()(cli/create_crew.py), the for-loop on line 214 usesprovideras its loop variable:This shadows the
providerparameter that's passed in from the CLI (crewai create crew <name> --provider <value>). After the loop finishes,providerno longer holds the user's original selection — it holds whatever the last key fromENV_VARSwas (or the key wherebreakwas hit).Currently the parameter isn't read again after the loop (the function uses
selected_providerfrom interactive selection instead), so this doesn't cause a visible behavioral issue today. But it's a latent bug — anyone adding code after the loop that referencesproviderwould silently get the wrong value. It also trips static analysis warnings and makes debugging confusing.Steps to Reproduce
create_crew()inlib/crewai/src/crewai/cli/create_crew.pyprovideras the loop variable infor provider, env_keys in ENV_VARS.items()print(provider)after the loop (line 221) and callcreate_crew("test", provider="openai")provideris no longer"openai"Expected behavior
The
providerparameter should retain its original value throughout the function. Loop variables should not shadow function parameters.Screenshots/Code snippets
Operating System
Ubuntu 22.04
Python Version
3.12
crewAI Version
1.13.0
crewAI Tools Version
1.13.0
Virtual Environment
Venv
Evidence
Standard Python scoping behavior — a
forloop variable persists after the loop and overwrites any variable with the same name in the enclosing scope. Any linter (pylint W0621, ruff) would flag this asredefined-from-outer-scope.Possible Solution
Rename the loop variable to
env_provider(or similar) so the parameter isn't clobbered. I have a one-line fix ready and will open a PR.Additional context
Side note: the
--providerCLI flag doesn't seem to actually bypass the interactive provider selection — the function always callsselect_provider()regardless. That's a separate issue though.