Skip to content

Fix airflow connections test returning success exit code on failure - #72548

Merged
henry3260 merged 1 commit into
apache:mainfrom
ColtenOuO:fix-connections-test-exit-code
Sep 6, 2026
Merged

henry3260 merged 1 commit into
apache:mainfrom
ColtenOuO:fix-connections-test-exit-code

Conversation

@ColtenOuO

Copy link
Copy Markdown
Contributor

Sumarry

airflow connections test <conn_id> prints "Connection failed!" but always returns exit code 0, because the failure branch in connections_test (airflow-core/src/airflow/cli/commands/connection_command.py) only prints
the error message without raising SystemExit(1). The other two failure paths in the same function (test-connection disabled, connection not found) already raise SystemExit(1), so this was an inconsistency rather than intentional behavior.

Any script that runs this command and checks $? (e.g. a deployment pre-flight check or a custom health check a deployment team wrote around this CLI) will treat a failed connection test as a success.

Change

This PR adds raise SystemExit(1) to the failure branch and updates test_cli_connections_test_fail to assert the exit code.

@Shriprasad-P Shriprasad-P left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the failure and success paths for connections_test().

On main, the disabled-test and missing-connection branches already exit with status 1, while the (False, message) branch only printed Connection failed! and returned, which propagated as shell exit code 0.

Adding raise SystemExit(1) after the existing failure message is consistent with the surrounding Airflow CLI behavior and preserves the current output without introducing duplicate stderr text.

The updated test now verifies both the existing failure message and exit code 1, while the success path remains unchanged. The bugfix newsfragment also correctly documents the scripting-visible behavior change.

LGTM.

@henry3260 henry3260 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix!

The failure branch in connections_test only printed the error message
without raising SystemExit(1), unlike the other two failure paths in
the same function. Any script that checks the exit code of this
command would treat a failed connection test as a success.
@ColtenOuO
ColtenOuO force-pushed the fix-connections-test-exit-code branch from ca860e6 to 4393d0d Compare September 6, 2026 05:18

@henry3260 henry3260 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for your contribution

@henry3260
henry3260 merged commit 2056378 into apache:main Sep 6, 2026
73 checks passed
@github-actions github-actions Bot added this to the Airflow 3.3.2 milestone Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.3.2 based on: backport label targeting v3-3-test
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-3-test PR Link

github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Sep 6, 2026
…on failure (apache#72548)

The failure branch in connections_test only printed the error message
without raising SystemExit(1), unlike the other two failure paths in
the same function. Any script that checks the exit code of this
command would treat a failed connection test as a success.
(cherry picked from commit 2056378)

Co-authored-by: Jyun-An Chen <jun930436@gmail.com>
aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Sep 6, 2026
…on failure (apache#72548)

The failure branch in connections_test only printed the error message
without raising SystemExit(1), unlike the other two failure paths in
the same function. Any script that checks the exit code of this
command would treat a failed connection test as a success.
(cherry picked from commit 2056378)

Co-authored-by: Jyun-An Chen <jun930436@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Sep 7, 2026
…on failure (#72548) (#72583)

The failure branch in connections_test only printed the error message
without raising SystemExit(1), unlike the other two failure paths in
the same function. Any script that checks the exit code of this
command would treat a failed connection test as a success.
(cherry picked from commit 2056378)

Co-authored-by: Jyun-An Chen <jun930436@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Sep 7, 2026
…on failure (#72548) (#72583)

The failure branch in connections_test only printed the error message
without raising SystemExit(1), unlike the other two failure paths in
the same function. Any script that checks the exit code of this
command would treat a failed connection test as a success.
(cherry picked from commit 2056378)

Co-authored-by: Jyun-An Chen <jun930436@gmail.com>
pierrejeambrun pushed a commit to astronomer/airflow that referenced this pull request Sep 8, 2026
…pache#72548)

The failure branch in connections_test only printed the error message
without raising SystemExit(1), unlike the other two failure paths in
the same function. Any script that checks the exit code of this
command would treat a failed connection test as a success.
imrichardwu pushed a commit to imrichardwu/airflow that referenced this pull request Sep 11, 2026
…pache#72548)

The failure branch in connections_test only printed the error message
without raising SystemExit(1), unlike the other two failure paths in
the same function. Any script that checks the exit code of this
command would treat a failed connection test as a success.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants