Fix XCom get_value outside task runner#68789
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
|
Hi, I don't think this is the right approach. The task-sdk should not be accessing the database directly. I would take a look at the docs here for a bit more detail on database access restrictions: |
cc8f502 to
cee3476
Compare
|
Updated the PR in cee3476 to avoid DB access from task-sdk. The revised patch restores BaseXCom to the supervisor-comms-only path, adds server-side XComModel.get_one()/get_value() helpers, exposes XComModel from the common compat SDK for plugin extra links, and adds /links route coverage for a plugin-registered extra link reading XCom through XComModel. |
|
This gives |
Plugin-registered extra links are resolved in the API server, but examples can naturally reach for
XCom.get_value()from the SDK/compat SDK. In Airflow 3 that SDK XCom path is task-runner scoped, so it expectsSUPERVISOR_COMMSand is not suitable for API-server extra-link code.This adds a server-side
XComModel.get_one()/XComModel.get_value()convenience path that reuses the existing metadata DB query and deserialization behavior fromXComModel. The common compat SDK now exposesXComModel, so plugin extra links can use an API-server-safe XCom reader without importing task-runtime SDK XCom.This also adds route coverage showing a plugin-registered extra link resolving through
/linksand reading an XCom value withXComModel.get_value().Closes #59093
Tests:
uv run pytest airflow-core/tests/unit/models/test_xcom.pyuv run pytest airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_extra_links.pyuv run pytest --rootdir=providers/common/compat providers/common/compat/tests/unit/common/compat/test_sdk.pyuv run pytest task-sdk/tests/task_sdk/bases/test_xcom.pyuv run ruff check airflow-core/src/airflow/models/xcom.py airflow-core/tests/unit/models/test_xcom.py airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_extra_links.py providers/common/compat/src/airflow/providers/common/compat/sdk.py providers/common/compat/tests/unit/common/compat/test_sdk.py task-sdk/src/airflow/sdk/bases/xcom.pyuv run ruff format --check airflow-core/src/airflow/models/xcom.py airflow-core/tests/unit/models/test_xcom.py airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_extra_links.py providers/common/compat/src/airflow/providers/common/compat/sdk.py providers/common/compat/tests/unit/common/compat/test_sdk.py task-sdk/src/airflow/sdk/bases/xcom.pyWas generative AI tooling used to co-author this PR?
Generated-by: OpenAI Codex following the guidelines at https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions