Repository navigation
Fix airflowctl ignoring --env for non-auth commands - #73808
Conversation
provide_api_client forwarded only api_token from the parsed args, so every decorated command resolved credentials for the production environment regardless of --env, and version --remote, which calls get_client directly, behaved the same. Pass the parsed env through get_client into Credentials, which still honours AIRFLOW_CLI_ENVIRONMENT over the explicit value. closes: apache#70519
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
|
Hi! This PR closes #70519 — It's my first PR to Airflow, so the CI workflows are queued waiting for approval — could a committer please approve the workflow run so the checks can execute? Any feedback on the approach is also very welcome. Thank you! |
Assert the parsed hostname instead of substring membership so the host under test is pinned exactly and CodeQL's python/url-substring-sanitization no longer flags the assertions.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Test imports violate repository checks, and newly added tests contain prohibited issue references and non-behavioral coverage.
Review effort: Balanced
Findings: 1
Open (6)
What changed in this PR
Fixes airflowctl environment selection so non-auth commands use credentials for the requested environment.
Changes:
- Propagates
--envthrough API-client creation. - Updates remote version lookup.
- Adds regression coverage for environment resolution.
| File | Description |
|---|---|
airflow-ctl/src/airflowctl/api/client.py |
Forwards environment selection to credentials. |
airflow-ctl/src/airflowctl/ctl/commands/version_command.py |
Applies environment selection to remote version requests. |
airflow-ctl/tests/airflow_ctl/api/test_client.py |
Tests client and decorator environment handling. |
airflow-ctl/tests/airflow_ctl/ctl/commands/test_version_command.py |
Tests remote version environment forwarding. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Move SimpleNamespace and provide_api_client imports to the module top (imports at top of file, no test-body imports). - Drop the GitHub issue reference and narrating docstrings from tests. - Remove test_defaults_to_production: it covers the pre-existing production default, which the testing standards exclude (every test must fail without the PR's change).
# Conflicts: # airflow-ctl/tests/airflow_ctl/api/test_client.py
Backport successfully created: airflow-ctl/v0-1-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…mmands (apache#73808) Honor --env when resolving airflowctl API credentials Forward the selected environment through decorated commands and version --remote, so staging requests use staging credentials. (cherry picked from commit aee26d4) Co-authored-by: kuse <[email protected]>
…mmands (#73808) (#75746) Honor --env when resolving airflowctl API credentials Forward the selected environment through decorated commands and version --remote, so staging requests use staging credentials. (cherry picked from commit aee26d4) Co-authored-by: kuse <[email protected]>
…mmands (#73808) (#75746) Honor --env when resolving airflowctl API credentials Forward the selected environment through decorated commands and version --remote, so staging requests use staging credentials. (cherry picked from commit aee26d4) Co-authored-by: kuse <[email protected]>


provide_api_clientforwarded onlyapi_tokenfrom the parsed args namespace, so every@provide_api_client-decorated command resolved credentials against the production environment no matter what--envthe user passed.version --remote, which callsget_clientdirectly, ignored--envthe same way even though the flag is attached to the command (cli_config.py:1313). Net effect:airflowctl dags list --env stagingsilently used production credentials — the failure mode described in the issue.closes: #70519
What changed
get_client()gainsapi_environmentand forwards it toCredentials, whose own contract (AIRFLOW_CLI_ENVIRONMENTbeats the explicit value) is preserved.provide_api_clientwrapper readsenvoff the parsed args namespace, falling back to"production"— the same defaultARG_AUTH_ENVIRONMENTandCredentialsuse, so callers that never pass--envare unaffected.version_command.version_infoforwards--envfor its directget_clientcall.This supersedes #70584, which was closed unmerged under the 5-open-PR limit rather than for its approach; the decorator and
version --remotepaths are now both covered by tests.Tests
TestGetClientEnvironment(airflow-ctl/tests/airflow_ctl/api/test_client.py): default stays production; explicitapi_environment="staging"resolvesstaging.json; same forNO_AUTH;AIRFLOW_CLI_ENVIRONMENTkeeps precedence; the decorator forwardsenvfrom the args namespace.test_version_command.py: the two mocked-call assertions updated for the new kwarg, plus a newtest_ctl_version_remote_with_envcovering--env staging.mainand pass on this branch (verified by stashing the source fix while keeping the tests).Was generative AI tooling used to co-author this PR?
Generated-by: [ZCode (GLM-5.3-Flash)] following the guidelines