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

   ## Summary
   
   When running `python my_dag.py` with `dag.test()` at the bottom, any
   `Variable.get()` at module level fails because `SUPERVISOR_COMMS` is not
   yet initialized. In production the DAG processor sets it before parsing,
   but the `dag.test()` / direct script execution flow does not.
   
   - Add module-level `__getattr__` in `task_runner.py` that lazily creates
     a `ParseTimeComms` when `SUPERVISOR_COMMS` is first accessed at parse time
   - `ParseTimeComms` queries the metadata DB directly via SQLAlchemy,
     avoiding the Execution API HTTP layer (which would cause a recursive
     deadlock: the API route detects SUPERVISOR_COMMS and delegates back to
     the SDK in an infinite loop)
   - Server processes (scheduler, API) are guarded via 
`_AIRFLOW_PROCESS_CONTEXT`
   - Falls back gracefully when DB is not configured (`settings.Session is 
None`)
   
   closes: #51816
   
   ## Test plan
   
   - [x] Unit tests for `__getattr__` behavior (4 tests in 
`test_task_runner.py`)
   - [x] Unit tests for `ParseTimeComms.send()` with mocked DB (4 tests in 
`test_supervisor.py`)
   - [x] Existing `test_variables.py` tests pass (9 tests)
   - [x] E2E via Breeze: DAG file with `Variable.get()` at top level + 
`dag.test()` resolves
         variable from DB, task executes successfully with the resolved value
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Opus 4.6)
   
   Generated-by: Claude Code (Opus 4.6) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


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