Skip to content

Conversation

@ramitkataria
Copy link
Contributor

In one of my previus PRs (#47648), I incorrectly assumed that catching the exception from secrets_backend.get_connection was meant for the connection not found case. So, I'm reversing a couple of changes from that PR for consistency.


^ 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.

In one of my previus PRs (apache#47648), I incorrectly assumed that catching the
exception from `secrets_backend.get_connection` was meant for the
connection not found case. So, I'm reversing a couple of changes from
that PR for consistency.
@ramitkataria ramitkataria requested review from XD-DENG and ashb as code owners May 8, 2025 00:17
@jason810496 jason810496 requested a review from amoghrajesh May 8, 2025 04:52
Copy link
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to do this, some nits

Copy link
Contributor

@ferruzzi ferruzzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable

@ferruzzi ferruzzi merged commit 84e8fc8 into apache:main May 12, 2025
51 checks passed
@ferruzzi ferruzzi deleted the ramitkataria/conn-exception branch May 12, 2025 17:43
return conn
except Exception:
log.debug(
log.exception(
Copy link
Member

@kaxil kaxil May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this logexception? It was correct before since we are looping through various secret backend here

cc @ramitkataria @amoghrajesh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally changed this to log.debug in PR #47648 because I misunderstood the behaviour. secrets_backend.get_connection returns None for "not found" cases and throws exceptions only for actual errors as far as I can tell. I encountered an issue with fernet keys where not logging the exception hid the actual error, showing only "Unable to retrieve connection from secrets backend (%s). Checking subsequent secrets backend." without any stack trace or error details which made it appear like the connection was just missing.

Using log.exception ensures that when there's a genuine error accessing a secrets backend (not just a missing connection), we get the full error details for debugging. We could also just set exc_info to True and keep using log.debug but this seems important enough for most users to know in case they're running into an issue where the connection exists but airflow can't find it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramitkataria The one you changed in PR #47648 is the different one I am referring to here. You already removed log.debug line you had added in that PR in this PR on line 481. The one I linked here is the one that loops across all secrets backends

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AH thanks.

kaxil added a commit to astronomer/airflow that referenced this pull request May 13, 2025
kaxil added a commit that referenced this pull request May 13, 2025
sanederchik pushed a commit to sanederchik/airflow that referenced this pull request Jun 7, 2025
…50329)

* Fix consistency in exception/log handling in `connection.py`

In one of my previus PRs (apache#47648), I incorrectly assumed that catching the
exception from `secrets_backend.get_connection` was meant for the
connection not found case. So, I'm reversing a couple of changes from
that PR for consistency.

* Change log message
sanederchik pushed a commit to sanederchik/airflow that referenced this pull request Jun 7, 2025
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Oct 22, 2025
This was an error in apache/airflow#50329

GitOrigin-RevId: d52f8b65fb5ab065e8f214cd00563945aef6d29f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants