seanmuth opened a new pull request, #68305:
URL: https://github.com/apache/airflow/pull/68305
`VaultBackend.get_connection()` constructed the returned `Connection` using
`airflow.models.connection.Connection` — the SQLAlchemy ORM model. In
Airflow 3,
instantiating this model triggers lazy mapper initialisation for the *entire*
Airflow model registry. In `PythonVirtualenvOperator` subprocesses (and other
isolated task contexts), `DagModel` has not been imported when the secrets
backend is consulted, so `DagScheduleAssetNameReference` cannot resolve its
`'DagModel'` relationship string, raising:
```
sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize
…
Triggering mapper: 'mapped class
DagScheduleAssetNameReference->dag_schedule_asset_name_reference'.
Original exception was: … expression 'DagModel' failed to locate a name
('DagModel').
```
Because `context.py`'s secrets-backend loop catches all exceptions at `DEBUG`
level (without `exc_info`), this error is silently swallowed. The connection
appears undefined even when Vault returns a valid `200` response with the
correct data.
**Fix:** switch to `airflow.providers.common.compat.sdk.Connection`, which
resolves to the Pydantic SDK `Connection` in Airflow 3 (no SQLAlchemy mapper
involvement) and falls back to the SQLAlchemy model in Airflow 2. For the
URI path, use `Connection.from_uri()` guarded by `AIRFLOW_V_3_0_PLUS` to
handle both Airflow versions correctly.
Two new regression tests verify that `get_connection()` returns an instance
of
the SDK `Connection` type rather than the SQLAlchemy ORM model.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Sonnet 4.6)
Generated-by: Claude Code (Sonnet 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]