junyeong0619 opened a new pull request, #66925:
URL: https://github.com/apache/airflow/pull/66925
## Summary
Removes two `airflow-core` imports from `_run_task` in
`task-sdk/src/airflow/sdk/definitions/dag.py`:
- `airflow.utils.session.create_session` (L1473) — sub-issue #54710.
`_run_task` now
takes a `session` keyword argument supplied by its caller (`dag.test`),
and uses it
for the inline `DEFERRED → SCHEDULED` transition after the trigger runs.
The write
is always performed; missing the session now fails loudly with `TypeError`
(no
silent skip — addresses the failure mode of the previous attempt at
#54933).
- `airflow.serialization.serialized_objects.create_scheduler_operator`
(L1484). The
single use site (`ti.task = create_scheduler_operator(...)`) mutates a
non-SQLAlchemy
Python attribute that nothing downstream reads (the caller re-resolves the
task via
`self.task_dict[ti.task_id]`). Confirmed dead by full test sweep — removed
along
with the import.
The test helper `run_task_instance` in
`devel-common/.../test_utils/taskinstance.py`
also calls `_run_task` directly, so it's updated to thread (or open) a
session
the same way.
## Scope clarification
The issue comment proposed moving "DB-write responsibility from `_run_task`
up to
its caller". This PR moves the **session ownership** to the caller while
keeping
the actual `session.add(ti) + session.commit()` inside `_run_task`. Hoisting
the
write itself (so `_run_task` becomes a pure single-attempt function and the
caller
drives the deferred-resume loop) is a larger refactor I'd like to keep as a
follow-up — happy to take that on if the design direction is preferred.
## Verification
- `breeze run pytest airflow-core/tests/unit/models/test_dag.py
airflow-core/tests/unit/cli/commands/test_dag_command.py
airflow-core/tests/unit/models/test_mappedoperator.py
airflow-core/tests/unit/models/test_xcom_arg.py` — 323 passed.
- DEFERRED → SCHEDULED resume specifically covered by
`test_dag_test_no_triggerer_running`.
- `prek run --from-ref upstream/main --stage pre-commit` — all checks pass.
- `prek run mypy-task-sdk` — pass.
closes: #54710
related: #61803
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 4.7)
Generated-by: Claude Code (Opus 4.7) 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]