-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Unify connection not found exceptions between AF2 and AF3 #52968
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
Unify connection not found exceptions between AF2 and AF3 #52968
Conversation
CC @jscheffl |
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.
We have the same try/except wrapping _get_connection in two places - is there a reason we don't handle inside that fn?
Shouldn't this be a bug fix too? |
I checked on this and I see the general trend:
|
Added 3.1 as I thought we are past the 3.0.3 deadline, but I realise we can do 3.0.4, marked it as such. |
@ramitkataria , you might want to take a look a this one |
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.
I can say this resolves the reported problem - Thanks!
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.
Looks good to me but I also agree with others about reducing code duplication where possible
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.
Also agree with it being a bugfix if we can still do that
yup, we can - 3.0.4 :) |
@kaxil will merging this PR interfere with the RC-X of 3.0.3? If so, i can hold it. (Although we have the 304 milestone set) |
Go for it, I will workaround it :) |
Cool thanks! |
Backport failed to create: v3-0-test. View the failure log Run details
You can attempt to backport this manually by running: cherry_picker 5c2a2ec v3-0-test This should apply the commit to the v3-0-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continue |
(cherry picked from commit 5c2a2ec)
Manual cherry pick here: #53093 |
closes: #52880
Problem
Accessing a connection from SDK (Connection or using context) in airflow 3 and if connection isn't found it raises:
AirflowRuntimeError: CONNECTION_NOT_FOUND: {'conn_id': 'my_conn'}
This is the case when pure SDK is used:
airflow.sdk.Connection
(airflow.models will work fine as we wrap it well)Airflow 2 raises:
airflow.exceptions.AirflowNotFoundException: The conn_id
my_connisn't defined
.Now due to this, some dags / providers use this for various sorts of filtering and for catching exceptions to perform some logic. So long term, this current way of handling exceptions is not feasible. We will start seeing problems when we start migrating providers to Airflow 3 entirely. Example issues: #52838 by amazon team and also #52921 by bosch team.
Testing the solution
DAG used:
Without the fix:
Accessing from context(task a):
Accessing from Models (task c):
Accessing from SDK:
After changes:
Accessing from context (task a):
Accessing from models (task b):
Accessing from SDK (task c):
^ 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.rst
or{issue_number}.significant.rst
, in airflow-core/newsfragments.