bujjibabukatta opened a new pull request, #70584:
URL: https://github.com/apache/airflow/pull/70584

   Ran into this while poking around the CLI — turns out --env/-e is accepted 
by pretty much every airflowctl command, but it's basically decorative outside 
of auth login. Everything else (dags list, connections list, dags trigger, you 
name it) quietly ignores it and talks to production no matter what you pass.
   
   The reason is that provide_api_client's wrapper only ever forwards api_token 
down to get_client(), and get_client() doesn't even accept an environment 
argument. So Credentials falls back to its own default of "production" every 
single time, regardless of what you typed. auth login works fine because it 
builds Credentials directly with api_environment=args.env — it just never went 
through this shared path.
   
   Practically, this means something like airflowctl dags trigger --env staging 
some_dag looks like it's targeting staging, but it's actually hitting 
production with whatever token happens to be sitting in the production keychain 
entry. Best case you get a confusing Token Expired/Invalid JWT error. Worst 
case it silently works — against the wrong environment.
   
   Fix is pretty small: get_client() now takes an api_environment param, and 
provide_api_client reads args.env and passes it through, same as auth login 
already does. While I was in there I noticed version_command.py had the exact 
same bug on its own direct get_client() call for version --remote --env ..., so 
fixed that too.
   
   AIRFLOW_CLI_ENVIRONMENT still takes priority over --env if both are set — 
that precedence already lived inside Credentials.__init__ and I didn't touch it.
   
   Added tests for both get_client (spins up real per-environment config files 
and checks it resolves the right one) and provide_api_client, which didn't 
actually have any direct test coverage before this.
   
   Closes #70519
   
   ## AI Disclosure
   
   - [x] This contribution used AI assistance.
   
   **Model(s) used:** Claude
   
   **AI was used for:**
   - Helping write this PR description.
   - Running the test suite locally to make sure everything passes before 
submitting.
   - Reviewing the implementation from a performance perspective.
   
   The implementation and code changes were developed and validated by me.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to