-
Notifications
You must be signed in to change notification settings - Fork 16.4k
AIP-72: Allow retrieving Connection from Task Context #45043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f812f2f to
518f485
Compare
kaxil
commented
Dec 18, 2024
ashb
reviewed
Dec 18, 2024
amoghrajesh
reviewed
Dec 18, 2024
304140b to
01a36d2
Compare
eef7296 to
38c6565
Compare
ashb
reviewed
Dec 18, 2024
- Added a minimal Connection user-facing object in Task SDK definition for use in the DAG file - Added logic to get Connections in the context. Fixed some bugs in the way related to Connection parsing/serializing!
38c6565 to
2937a0c
Compare
amoghrajesh
reviewed
Dec 19, 2024
ashb
approved these changes
Dec 19, 2024
Member
ashb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments have been addressed
amoghrajesh
approved these changes
Dec 19, 2024
Contributor
amoghrajesh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments lying open, rest LGTM
Closed
4 tasks
got686-yandex
pushed a commit
to got686-yandex/airflow
that referenced
this pull request
Jan 30, 2025
part of apache#44481 - Added a minimal Connection user-facing object in Task SDK definition for use in the DAG file - Added logic to get Connections in the context. Fixed some bugs in the way related to Connection parsing/serializing! Now, we have following Connection related objects: - `ConnectionResponse` is auto-generated and tightly coupled with the API schema. - `ConnectionResult` is runtime-specific and meant for internal communication between Supervisor & Task Runner. - `Connection` class here is where the public-facing, user-relevant aspects are exposed, hiding internal details. **Next up**: - Same for XCom & Variable - Implementation of BaseHook.get_conn Tested it with a DAG: <img width="1711" alt="image" src="https://github.com/user-attachments/assets/14d28fb7-f6c5-4fbe-b226-46873af2d0f3" /> DAG: ```py from __future__ import annotations from airflow.models.baseoperator import BaseOperator from airflow.models.dag import dag class CustomOperator(BaseOperator): def execute(self, context): import os os.environ["AIRFLOW_CONN_AIRFLOW_DB"] = "sqlite:///home/airflow/airflow.db" task_id = context["task_instance"].task_id print(f"Hello World {task_id}!") print(context) print(context["conn"].airflow_db) assert context["conn"].airflow_db.conn_id == "airflow_db" @dag() def super_basic_run(): CustomOperator(task_id="hello") super_basic_run() ``` For case where a **connection is not found** <img width="1435" alt="image" src="https://github.com/user-attachments/assets/7c5e0cb4-6ed4-41aa-9a57-e5641adce954" />
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
part of #44481
Now, we have following Connection related objects:
ConnectionResponseis auto-generated and tightly coupled with the API schema.ConnectionResultis runtime-specific and meant for internal communication between Supervisor & Task Runner.Connectionclass here is where the public-facing, user-relevant aspects are exposed, hiding internal details.Next up:
Tested it with a DAG:
DAG:
For case where a connection is not found
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in newsfragments.