You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "amoghrajesh (via GitHub)" <gi...@apache.org> on 2025/08/20 08:33:28 UTC
[I] Remove `airflow.utils.session` references in task-sdk [airflow]
amoghrajesh opened a new issue, #54710:
URL: https://github.com/apache/airflow/issues/54710
### Body
Current Usage:
`task-sdk/src/airflow/sdk/definitions/dag.py`
### Committer
- [x] I acknowledge that I am a maintainer/committer of the Apache Airflow project.
--
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.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Remove `airflow.utils.session` references in task-sdk [airflow]
Posted by "aayushbisen (via GitHub)" <gi...@apache.org>.
aayushbisen commented on issue #54710:
URL: https://github.com/apache/airflow/issues/54710#issuecomment-3222897052
## Existing use of session util
The `_run_task()` helper function was creating its own database session using:
```python
from airflow.utils.session import create_session
# Later in the code:
with create_session() as session:
ti.state = State.SCHEDULED
session.add(ti)
```
This created an unwanted dependency on airflow core utilities from within the task-sdk.
## Solution
Refactored the session management to reuse the existing session from the parent `test()` method instead of creating a new one:
1. **Modified function signature**: Added optional `session=None` parameter to `_run_task()`
2. **Removed problematic import**: Eliminated `from airflow.utils.session import create_session`
3. **Updated session usage**: Replaced context manager with direct session usage when provided
4. **Updated function call**: Pass the existing session from the `test()` method
**Before:**
```python
def _run_task(*, ti, task, run_triggerer=False):
# ...
if ti.state == State.DEFERRED and isinstance(msg, DeferTask) and run_triggerer:
from airflow.utils.session import create_session
# ...
with create_session() as session:
ti.state = State.SCHEDULED
session.add(ti)
```
**After:**
```python
def _run_task(*, ti, task, run_triggerer=False, session=None):
# ...
if ti.state == State.DEFERRED and isinstance(msg, DeferTask) and run_triggerer:
# ...
if session is not None:
ti.state = State.SCHEDULED
session.add(ti)
```
--
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: [I] Remove `airflow.utils.session` references in task-sdk [airflow]
Posted by "aayushbisen (via GitHub)" <gi...@apache.org>.
aayushbisen commented on issue #54710:
URL: https://github.com/apache/airflow/issues/54710#issuecomment-3210331153
Hey @amoghrajesh I would like to work on this issue.
--
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: [I] Remove `airflow.utils.session` references in task-sdk [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on issue #54710:
URL: https://github.com/apache/airflow/issues/54710#issuecomment-3211550605
Feel free.
--
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: [I] Remove `airflow.utils.session` references in task-sdk [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on issue #54710:
URL: https://github.com/apache/airflow/issues/54710#issuecomment-3986441875
@aayushbisen We are unassigning you from this issue as part of our updated [assignment policy](https://github.com/apache/airflow/blob/main/contributing-docs/04_how_to_contribute.rst#contribute-code-changes).
This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.
We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.
--
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: [I] Remove `airflow.utils.session` references in task-sdk [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on issue #54710:
URL: https://github.com/apache/airflow/issues/54710#issuecomment-4707215982
Wasn't committed for Airflow 3.3, moving to Airflow 3.4 as best effort work.
--
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: [I] Remove `airflow.utils.session` references in task-sdk [airflow]
Posted by "aayushbisen (via GitHub)" <gi...@apache.org>.
aayushbisen commented on issue #54710:
URL: https://github.com/apache/airflow/issues/54710#issuecomment-3213141461
Where should the session utility be moved from the current folder? I am thinking like
```python
# Before:
from airflow.utils.session import create_session
# After:
from airflow.sdk.utils.session import create_session
```
--
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