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

   ## Why
   
   - `airflow config list` prints a `# Variable:` line for each option when 
`--include-env-vars` or `--defaults` is set.
   - For sections with a dot (like `providers.odbc`), Airflow reads 
`AIRFLOW__PROVIDERS_ODBC__ALLOW_DRIVER_IN_EXTRA`, but the line showed 
`AIRFLOW__PROVIDERS.ODBC__ALLOW_DRIVER_IN_EXTRA`. Setting that variable has no 
effect. The [Setting Configuration 
Options](https://airflow.apache.org/docs/apache-airflow/stable/howto/set-config.html)
 page says to replace a dot in the section name with an underscore.
   - For team-specific sections such as `[team_a=celery]`, Airflow reads 
`AIRFLOW__TEAM_A___CELERY__WORKER_CONCURRENCY`, but the line showed 
`AIRFLOW__TEAM_A=CELERY__WORKER_CONCURRENCY`. The 
[Multi-Team](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/multi-team.html#via-environment-variables)
 page documents the `AIRFLOW__{TEAM}___{SECTION}__{KEY}` format.
   
   ## How
   
   - `_write_option_header` now gets the name from `_env_var_name`, the method 
the parser uses to read environment variables.
   - For a team-specific section, the team name is split off the section name 
at the last `=` and passed as `team_name`.
   
   
   ## Verification
   
   - Unit test: `uv run --frozen --project shared/configuration pytest 
shared/configuration/tests`
   - Integration test:
   
   1. Setup
   
   ```sh
   export AIRFLOW_HOME="${TMPDIR:-/tmp}/airflow-config-list-demo/airflow-home"
   mkdir -p "$AIRFLOW_HOME"
   cat > "$AIRFLOW_HOME/airflow.cfg" <<'EOF'
   [team_a=celery]
   worker_concurrency = 8
   EOF
   uv run --frozen --project providers/odbc airflow config get-value 
providers.odbc allow_driver_in_extra | tail -n 1
   uv run --frozen --project providers/odbc python -c 'from 
airflow.configuration import conf; print(conf.get("celery", 
"worker_concurrency", team_name="team_a"))'
   ```
   
   Its output is:
   
   ```text
   False
   8
   ```
   
   2. Check `airflow config list --defaults` prints and set it for the command 
that reads the option back.
   
   ```bash
   export AIRFLOW_HOME="${TMPDIR:-/tmp}/airflow-config-list-demo/airflow-home"
   ODBC_VAR=$(uv run --frozen --project providers/odbc airflow config list 
--defaults --show-values --section providers.odbc | sed -n 's/^# Variable: //p')
   echo "$ODBC_VAR"
   env "$ODBC_VAR=True" uv run --frozen --project providers/odbc airflow config 
get-value providers.odbc allow_driver_in_extra | tail -n 1
   TEAM_VAR=$(uv run --frozen --project providers/odbc airflow config list 
--defaults --show-values --section team_a=celery | sed -n 's/^# Variable: //p')
   echo "$TEAM_VAR"
   env "$TEAM_VAR=16" uv run --frozen --project providers/odbc python -c 'from 
airflow.configuration import conf; print(conf.get("celery", 
"worker_concurrency", team_name="team_a"))'
   ```
   
   On the main branch, the setting doesn't take effect, so reading 
configuration fallbacks to default value:
   
   ```text
   AIRFLOW__PROVIDERS.ODBC__ALLOW_DRIVER_IN_EXTRA
   False
   AIRFLOW__TEAM_A=CELERY__WORKER_CONCURRENCY
   8
   ```
   
   On this branch, it shows correct variable and the value takes effect:
   
   ```text
   AIRFLOW__PROVIDERS_ODBC__ALLOW_DRIVER_IN_EXTRA
   True
   AIRFLOW__TEAM_A___CELERY__WORKER_CONCURRENCY
   16
   ```
    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull 
request.
   Write a good git commit message following this guide: 
https://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the 
documentation.
   
   For user-facing UI changes, please attach before/after screenshots (or a 
short
   screen recording) so reviewers can assess the visual impact.
   
   Feel free to ping (in general) for the review if you do not see reaction for 
a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we 
sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change below checkbox to `[X]` followed by the name of the tool, uncomment 
the "Generated-by".
   -->
   
   - [X] Yes - Claude Code
   
   <!--
   Generated-by: [Tool Name] following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
 You can add this file in a follow-up commit after the PR is created so you 
know the PR number.
   


-- 
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