You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "uplsh580 (via GitHub)" <gi...@apache.org> on 2026/01/25 11:19:03 UTC
[PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
uplsh580 opened a new pull request, #61036:
URL: https://github.com/apache/airflow/pull/61036
## Related Issues
Issue: https://github.com/apache/airflow/issues/61033
## Summary
This PR ensures that Airflow CLI commands are executed with the `server` process context by default.
This is achieved by setting the `_AIRFLOW_PROCESS_CONTEXT` environment variable to `"server"` within the core CLI decorators (`action_cli` and `suppress_logs_and_warning`).
## Rationale
Previously, commands like `airflow dag-processor -B <bundle_name>` failed with an `AirflowNotFoundException` when initializing bundles that require database connections (e.g., `GitDagBundle`).
The failure occurred because:
1. The `-B` flag triggers bundle validation (`validate_dag_bundle_arg`) during the command initialization phase.
2. At this early stage, the `server` context was not yet set, causing the Task SDK to skip `MetastoreBackend` and fail to resolve connections from the metadata database.
By moving the context setting to the decorator level, we ensure that all CLI management commands have the necessary privileges to access database-backed secrets before any validation or execution logic runs.
## Key Changes
- **`airflow/utils/cli.py`**:
- Set `_AIRFLOW_PROCESS_CONTEXT = "server"` in `action_cli` decorator when `check_db` is True.
- Set `_AIRFLOW_PROCESS_CONTEXT = "server"` in `suppress_logs_and_warning` decorator.
- **`airflow/cli/commands/connection_command.py`**: Removed redundant manual environment settings in `connections_get` and `connections_test`.
- **Tests**: Added unit tests in `tests/unit/utils/test_cli_util.py` to verify the environment variable is correctly set during CLI execution.
## Test plan
1. Configure a DAG bundle that requires a connection (e.g., GitDagBundle).
2. Run `airflow dag-processor -B <bundle_name>`.
3. Verify the command starts successfully without `AirflowNotFoundException`.
4. Run existing connection commands (e.g., `airflow connections get`) to ensure no regressions.
<!--
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: http://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.
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 (please specify the tool below)
- Gemini 3 flash
<!--
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` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #61036:
URL: https://github.com/apache/airflow/pull/61036#discussion_r2927763013
##########
airflow-core/src/airflow/utils/cli.py:
##########
@@ -101,7 +101,12 @@ def wrapper(*args, **kwargs):
root_logger.setLevel(logging.DEBUG)
for handler in root_logger.handlers:
handler.setLevel(logging.DEBUG)
+ # Save original value and restore after context ends
+ original_value = os.environ.get("_AIRFLOW_PROCESS_CONTEXT")
try:
+ # Set process context to "server" for the entire function execution
+ # This ensures connection resolution works correctly throughout the CLI command
Review Comment:
**Bug / Design issue**: The process context is set unconditionally, but the PR description says it should only be set "when `check_db` is True". More importantly, setting `server` context for **every** `action_cli`-decorated command is overly broad — it grants MetastoreBackend access to commands that don't need it (e.g., `airflow info`, `airflow cheat-sheet`).
The original bug is specifically about `dag-processor -B` needing server context for `validate_dag_bundle_arg()`. A more targeted fix would be to set server context only where it's actually needed.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on code in PR #61036:
URL: https://github.com/apache/airflow/pull/61036#discussion_r2934718031
##########
airflow-core/tests/unit/cli/commands/test_dag_processor_command.py:
##########
@@ -57,6 +57,29 @@ def test_bundle_names_passed(self, mock_runner, configure_testing_dag_bundle):
dag_processor_command.dag_processor(args)
assert mock_runner.call_args.kwargs["processor"].bundle_names_to_parse == ["testing"]
+ @conf_vars({("core", "load_examples"): "False"})
+ @mock.patch("airflow.cli.commands.dag_processor_command.DagProcessorJobRunner")
+ @mock.patch("airflow.utils.cli.DagBundlesManager", autospec=True)
+ def test_bundle_validation_runs_with_server_context(self, mock_manager_cls, mock_runner):
+ mock_runner.return_value.job_type = "DagProcessorJob"
+ captured_ctx = {}
+
+ mock_bundle = mock.MagicMock()
+ mock_bundle.name = "bundle1"
+
+ def capture_env_and_return_bundles():
+ captured_ctx["during_validation"] = os.environ.get("_AIRFLOW_PROCESS_CONTEXT")
+ return [mock_bundle]
+
+ mock_manager_cls.return_value.get_all_dag_bundles.side_effect = capture_env_and_return_bundles
+
+ os.environ.pop("_AIRFLOW_PROCESS_CONTEXT", None)
Review Comment:
Addressed the env var leak risk by switching to `monkeypatch.delenv("_AIRFLOW_PROCESS_CONTEXT", raising=False)` instead of `os.environ.pop`.
Thanks
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-3803291993
Thanks @potiuk!
Yeah we want to get rid of using that env variable entirely in long term but for dag processor and such, it will be dependent also on AIP92 (entirely decoupling dag processor and triggerer from core and having API first communication for those too). So this would be a good temporary solution until then
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on code in PR #61036:
URL: https://github.com/apache/airflow/pull/61036#discussion_r2725430682
##########
airflow-core/src/airflow/utils/cli.py:
##########
@@ -436,6 +437,7 @@ def suppress_logs_and_warning(f: T) -> T:
@functools.wraps(f)
def _wrapper(*args, **kwargs):
_check_cli_args(args)
+ os.environ["_AIRFLOW_PROCESS_CONTEXT"] = "server"
Review Comment:
Query-type CLI commands (e.g., `dags list`) require the server context to successfully initialize DAG bundles that depend on database-stored connections. Providing the context here ensures consistent secret resolution via MetastoreBackend across all read-only administrative tools. This centralization also allows for the removal of redundant manual environment settings within individual command functions like `connections_get`.
##########
airflow-core/src/airflow/utils/cli.py:
##########
@@ -107,6 +107,7 @@ def wrapper(*args, **kwargs):
from airflow.configuration import conf
from airflow.utils.db import check_and_run_migrations, synchronize_log_template
+ os.environ["_AIRFLOW_PROCESS_CONTEXT"] = "server"
Review Comment:
Setting the server context here ensures that state-changing or heavy CLI commands (like `dag-processor`, `db migrate`, or `tasks run`) have the necessary privileges to access database-backed secrets. This is particularly crucial for commands like `airflow dag-processor -B,` where DAG bundle validation occurs during the command's initialization phase, before the actual Job runner starts.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on code in PR #61036:
URL: https://github.com/apache/airflow/pull/61036#discussion_r2725430682
##########
airflow-core/src/airflow/utils/cli.py:
##########
@@ -436,6 +437,7 @@ def suppress_logs_and_warning(f: T) -> T:
@functools.wraps(f)
def _wrapper(*args, **kwargs):
_check_cli_args(args)
+ os.environ["_AIRFLOW_PROCESS_CONTEXT"] = "server"
Review Comment:
Query-type CLI commands (e.g., `dags list`) require the server context to successfully initialize DAG bundles that depend on database-stored connections. Providing the context here ensures consistent secret resolution via MetastoreBackend across all read-only administrative tools. This centralization also allows for the removal of redundant manual environment settings within individual command functions like `connections_get`.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-4059617741
# Validation
## `airflow dag-processor -B bundle1` from connection in db
<img width="1246" height="578" alt="image" src="https://github.com/user-attachments/assets/f19d5be7-0ae6-428c-beb0-81f806fc5f29" />
<img width="1470" height="956" alt="image" src="https://github.com/user-attachments/assets/41813b46-559b-4a28-b42c-98e67e16c19b" />
## `airflow dag-processor -B bundle1` from CONN ENV
<img width="1186" height="337" alt="image" src="https://github.com/user-attachments/assets/72f93f10-f19b-42d9-a745-778398fa7688" />
<img width="1470" height="923" alt="image" src="https://github.com/user-attachments/assets/7777e344-8bbf-445a-9d14-6686ed9ff5c8" />
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-3801678210
Thanks, @potiuk! You summarised it pretty clearly. We will have deprecations on the CLI and will start this pretty soon. In CLI, there will be isolation work on remote commands defined in [AIP-81](https://cwiki.apache.org/confluence/display/AIRFLOW/AIP-81+Enhanced+Security+in+CLI+via+Integration+of+API). Deprecation and migration are on the way. Airflow CLI will mainly be used for always server-side triggers and actions rather than anything we can safely provide from the API.
The voting will start later today or tomorrow. There are incoming dev call, and I wanted to align the voting so we can maybe go over it all together with everyone in the call to see if there are any concerns which most of the part already agreed on in `AIP-81`, but we now have a more concrete plan on how to achieve it in `AIP-94` and will be voted from entire community.
https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=382175838
For the TaskSDK side, @amoghrajesh can have a clearer answer
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-3804507562
@uranusjr Thanks for the feedback. I've updated the logic to ensure the environment variable is restored when the context ends, avoiding any global state leakage. I appreciate the suggestion!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-4056397776
# Validation
## With ENV CONN - `AIRFLOW_CONN_GITHUB__SAMPLE`
<img width="1223" height="267" alt="image" src="https://github.com/user-attachments/assets/4be63dad-1169-416d-8ea2-885097f71f7e" />
<img width="1457" height="909" alt="스크린샷 2026-03-14 오전 1 26 33" src="https://github.com/user-attachments/assets/dafa5535-c13c-416a-8576-27471f419577" />
## With Connection from db
<img width="1898" height="640" alt="image" src="https://github.com/user-attachments/assets/f5232793-68da-4f81-a985-d1a395c5ad29" />
<img width="1457" height="909" alt="스크린샷 2026-03-14 오전 1 23 32" src="https://github.com/user-attachments/assets/af338892-e048-4be6-ae02-7707280ac551" />
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-3796514018
Could you please verify if this approach aligns with the project's long-term architectural goals regarding component isolation and database access?
I believe this change is consistent with our future direction for the following reasons:
1. **Administrative Identity**: CLI tools are inherently administrative and designed for system management. Even as we move towards greater component isolation, these management commands require a 'Server' identity to resolve credentials and initialize system components effectively.
2. **Architectural Consistency**: This PR utilizes the existing `_AIRFLOW_PROCESS_CONTEXT` abstraction defined for Airflow 3. Centralizing this setting within the core CLI decorators ensures the correct context is established at the initial entry point, preventing early initialization failures during bundle validation.
3. **Security Isolation**: Importantly, this does not compromise the isolation of user code. The actual task execution and DAG parsing remain strictly restricted, as the Task SDK's Supervisor and the DAG processor explicitly override the context to `client` for child processes to prevent inheriting server privileges:
* [airflow-core/src/airflow/dag_processing/processor.py#L180-L183](https://github.com/apache/airflow/blob/0cf89fa362e72898b718fe6ff2fc8caa0b4ba45f/airflow-core/src/airflow/dag_processing/processor.py#L180-L183)
* [task-sdk/src/airflow/sdk/execution_time/supervisor.py#L921-L923](https://github.com/apache/airflow/blob/0cf89fa362e72898b718fe6ff2fc8caa0b4ba45f/task-sdk/src/airflow/sdk/execution_time/supervisor.py#L921-L923)
Your feedback on whether this centralization is the preferred way to handle CLI context would be greatly appreciated.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-3796479709
# Validation
```
airflow dag-processor -B bundle1
```
<img width="1251" height="682" alt="image" src="https://github.com/user-attachments/assets/be0d56db-efb1-4048-b889-0f64c5cf5aba" />
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #61036:
URL: https://github.com/apache/airflow/pull/61036
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #61036:
URL: https://github.com/apache/airflow/pull/61036#discussion_r2933870179
##########
airflow-core/src/airflow/cli/commands/dag_processor_command.py:
##########
@@ -35,7 +36,15 @@
def _create_dag_processor_job_runner(args: Any) -> DagProcessorJobRunner:
"""Create DagFileProcessorProcess instance."""
if args.bundle_name:
Review Comment:
nOte: `_create_dag_processor_job_runner` is called from within the `dag_processor` function, which is already wrapped by `@cli_utils.action_cli`. The `action_cli` decorator runs `check_and_run_migrations()` (when `check_db=True`) before calling the wrapped function, so the DB is available at this point. The issue is specifically that `_AIRFLOW_PROCESS_CONTEXT` isn't set, which affects the Task SDK's secret backend resolution.
This is fine as-is, but a comment explaining *why* the context needs to be set here would help future readers understand the dependency on `MetastoreBackend`.
##########
airflow-core/tests/unit/cli/commands/test_dag_processor_command.py:
##########
@@ -57,6 +57,29 @@ def test_bundle_names_passed(self, mock_runner, configure_testing_dag_bundle):
dag_processor_command.dag_processor(args)
assert mock_runner.call_args.kwargs["processor"].bundle_names_to_parse == ["testing"]
+ @conf_vars({("core", "load_examples"): "False"})
+ @mock.patch("airflow.cli.commands.dag_processor_command.DagProcessorJobRunner")
+ @mock.patch("airflow.utils.cli.DagBundlesManager", autospec=True)
+ def test_bundle_validation_runs_with_server_context(self, mock_manager_cls, mock_runner):
+ mock_runner.return_value.job_type = "DagProcessorJob"
+ captured_ctx = {}
+
+ mock_bundle = mock.MagicMock()
+ mock_bundle.name = "bundle1"
+
+ def capture_env_and_return_bundles():
+ captured_ctx["during_validation"] = os.environ.get("_AIRFLOW_PROCESS_CONTEXT")
+ return [mock_bundle]
+
+ mock_manager_cls.return_value.get_all_dag_bundles.side_effect = capture_env_and_return_bundles
+
+ os.environ.pop("_AIRFLOW_PROCESS_CONTEXT", None)
Review Comment:
**Bug: Environment variable leak risk in test.**
`os.environ.pop("_AIRFLOW_PROCESS_CONTEXT", None)` modifies the real `os.environ` without restoring the original value after the test. If another test in the same process previously set this variable, this test silently removes it. Use `monkeypatch.delenv` or wrap the mutation in a try/finally:
```python
def test_bundle_validation_runs_with_server_context(self, mock_manager_cls, mock_runner, monkeypatch):
...
monkeypatch.delenv("_AIRFLOW_PROCESS_CONTEXT", raising=False)
...
```
Also, the assertion on line 81 (`assert "_AIRFLOW_PROCESS_CONTEXT" not in os.environ`) verifies cleanup, but if the test itself fails before that line, the env var could remain set and leak into subsequent tests.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #61036:
URL: https://github.com/apache/airflow/pull/61036#discussion_r2933868112
##########
airflow-core/src/airflow/cli/commands/dag_processor_command.py:
##########
@@ -35,7 +36,15 @@
def _create_dag_processor_job_runner(args: Any) -> DagProcessorJobRunner:
"""Create DagFileProcessorProcess instance."""
if args.bundle_name:
- cli_utils.validate_dag_bundle_arg(args.bundle_name)
+ original_ctx = os.environ.get("_AIRFLOW_PROCESS_CONTEXT")
Review Comment:
**Suggestion: Consider setting the context in the `action_cli` decorator instead.**
This fix is scoped to just this one call site, but the underlying problem (CLI commands needing server context before validation logic runs) could affect other commands too. Setting `_AIRFLOW_PROCESS_CONTEXT = "server"` inside the `action_cli` decorator (when `check_db=True`) would provide a centralized solution and match what the PR description actually claims to do.
If a localized fix is preferred, that's acceptable — but then the PR description should be updated to match the actual implementation.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-3803310826
The logic looks right to me, but I don’t like how a decorator magically modifies the global state (an environment variable) that _leaks out after it exits_. If we’re to do this, the environment varialbe needs to be restored when the context ends.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-3804496491
## Validation
### Issue case - `airflow dag-processor -B bundle1`
<img width="1581" height="804" alt="image" src="https://github.com/user-attachments/assets/709fd2d8-d70e-4512-a404-cb9c988bfe95" />
### `airflow dag-processor`
<img width="1888" height="975" alt="스크린샷 2026-01-27 오후 7 54 00" src="https://github.com/user-attachments/assets/41b213ae-42df-4d66-859e-2dd3983441d4" />
### `airflow connections get GITHUB__SAMPLE`
<img width="1646" height="391" alt="image" src="https://github.com/user-attachments/assets/f4bb8d66-3a3d-4076-8c49-e7f9f037a46b" />
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-3799404773
I think we are going to get rid of `_AIRFLOW_PROCESS_CONTEXT` altogether - correct @amoghrajesh @bugraoz93 ? - so rather than moving it around, I would wait for completing the isolation process, where if needed we pass the necessary context to "shared" library from the calling process via some parameter during the initialization.
Some of the cli methods are shared between `airflow-ctl` and `airflow` regular CLI commands, and this will be the main distinction that will determine whether the DB calls are made or CLI calls - and then, it will not be necessary to have an enviironment variable to pass the context. This is - as I see it - a bit of a hack to make it possible to use the same code in two places - and the current shared library context is taking another - more long term - approach, similarly the initialization will be more of a deliberate process where just "importing" airflow is not going to to do much - there will be a deliberate initialization code that will depend on which component is running the initialization and passign the right "context" via this initialization to the shared code seems to be a better approach.
Maybe we can merge it as a temporary measure, but I don't see it as even mid-term sustainable approach.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-3902709677
@uranusjr -> are you ok with it ?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on code in PR #61036:
URL: https://github.com/apache/airflow/pull/61036#discussion_r2934717224
##########
airflow-core/src/airflow/cli/commands/dag_processor_command.py:
##########
@@ -35,7 +36,15 @@
def _create_dag_processor_job_runner(args: Any) -> DagProcessorJobRunner:
"""Create DagFileProcessorProcess instance."""
if args.bundle_name:
- cli_utils.validate_dag_bundle_arg(args.bundle_name)
+ original_ctx = os.environ.get("_AIRFLOW_PROCESS_CONTEXT")
Review Comment:
Updated `action_cli` so that server context is set only when `check_db=True`. Thanks for the feedback.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #61036:
URL: https://github.com/apache/airflow/pull/61036#issuecomment-4058105377
@uplsh580 This PR has been converted to **draft** because it does not yet meet our [Pull Request quality criteria](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-quality-criteria).
**Issues found:**
- :x: **Build docs**: Failing: CI image checks / Build documentation (--docs-only). Run `breeze build-docs` locally to reproduce. See [Build docs docs](https://github.com/apache/airflow/blob/main/contributing-docs/16_documentation.rst).
- :x: **Other failing CI checks**: Failing: CI image checks / Build documentation (--spellcheck-only). Run `prek run --from-ref main` locally to reproduce. See [static checks docs](https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst).
- :warning: **Unresolved review comments**: This PR has 1 unresolved review thread from maintainers: **@potiuk** (MEMBER): 1 unresolved thread. Please review and resolve all inline review comments before requesting another review. You can resolve a conversation by clicking 'Resolve conversation' on each thread after addressing the feedback. See [pull request guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst).
> **Note:** Your branch is **437 commits behind `main`**. Some check failures may be caused by changes in the base branch rather than by your PR. Please rebase your branch and push again to get up-to-date CI results.
**What to do next:**
- The comment informs you what you need to do.
- Fix each issue, then mark the PR as "Ready for review" in the GitHub UI - but only after making sure that all the issues are fixed.
- Maintainers will then proceed with a normal review.
Converting a PR to draft is **not** a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. If you have questions, feel free to ask on the [Airflow Slack](https://s.apache.org/airflow-slack).
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix connection resolution in CLI by setting server process context in decorators [airflow]
Posted by "uplsh580 (via GitHub)" <gi...@apache.org>.
uplsh580 commented on code in PR #61036:
URL: https://github.com/apache/airflow/pull/61036#discussion_r2725426309
##########
airflow-core/src/airflow/utils/cli.py:
##########
@@ -107,6 +107,7 @@ def wrapper(*args, **kwargs):
from airflow.configuration import conf
from airflow.utils.db import check_and_run_migrations, synchronize_log_template
+ os.environ["_AIRFLOW_PROCESS_CONTEXT"] = "server"
Review Comment:
Setting the server context here ensures that state-changing or heavy CLI commands (like `dag-processor`, `db migrate`, or `tasks run`) have the necessary privileges to access database-backed secrets. This is particularly crucial for commands like `airflow dag-processor -B,` where DAG bundle validation occurs during the command's initialization phase, before the actual Job runner starts.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org