Fix : 'airflow connections test' failure by adding DB fallback#59038
Fix : 'airflow connections test' failure by adding DB fallback#59038anshuksi282-ksolves wants to merge 1 commit intoapache:mainfrom
Conversation
Test a connection Positional Arguments: conn_id Connection id, required to get/add/delete/test a connection Options: -h, --help show this help message and exit -v, --verbose Make logging output more verbose fails to resolve connection by conn_id
potiuk
left a comment
There was a problem hiding this comment.
That's not the right way of solving it.
Currently get_connection_from_secrets (and it's likely a misleading name but we have to keep it for compatibility) - will retrieve connection from configured secret backends and it will do it in the sequence the backends are configured.
Currently, the backends are always in predefined order but we have a change in progress #45931 that will allow to configure the order.
And connection list is different. connection list will only ever list connections that you have in database and nothing else, because there is no "enumeration" possibility when using the secrets backends.
So - I am not sure if there is anything to fix.
If you have backend configured and run connection.get and it fails with anything else than "NOT FOUND" - it should indeed fail, because it's possible that connection.get should return the connection from secret - not the one from the database.
So I think we should just close that issue.
|
I am not even sure if that is the actual problem that was described in #58567 |
Description
This PR resolves an issue where the
airflow connections testCLI command would fail with "Connection not found" or "conn_id isn't defined", even when the connection was clearly visible usingairflow connections list.The Issue:
Previously,
connections_testrelied solely onConnection.get_connection_from_secrets(args.conn_id). If the secrets backend failed to retrieve the connection (e.g., due to environment issues or Hook initialization failures), the CLI would exit with an error, ignoring the fact that the connection might exist in the Metastore Database.In contrast,
connections_listqueries the database directly, creating a discrepancy between the two commands.The Fix:
I have updated
airflow/cli/commands/connection_command.pyto implement a fallback mechanism:AirflowNotFoundExceptionor returnsNone), it now explicitly checks the Database usingcreate_session.Related Issue
Closes #58567
^ 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 airflow-core/newsfragments.