Skip to content

fix: raise exception in is_merged() for non-204/non-404 status codes#3466

Open
Aliipou wants to merge 1 commit intoPyGithub:mainfrom
Aliipou:fix/is-merged-error-handling
Open

fix: raise exception in is_merged() for non-204/non-404 status codes#3466
Aliipou wants to merge 1 commit intoPyGithub:mainfrom
Aliipou:fix/is-merged-error-handling

Conversation

@Aliipou
Copy link
Copy Markdown

@Aliipou Aliipou commented Mar 22, 2026

Summary

Fixes #2760

PullRequest.is_merged() previously used raw requestJson() which silently returned False for any non-204 status code, including:

  • 401 Bad credentials (expired/invalid token)
  • 403 Forbidden
  • Any other HTTP error

This caused false negatives where an expired authentication token would cause is_merged() to return False instead of raising the appropriate exception, differing from all other PyGithub methods.

Changes

The method now explicitly handles each case:

  • 204 returns True (PR is merged)
  • 404 returns False (PR is not merged)
  • Any other status raises the appropriate GithubException

A test with replay data is included to verify the 401 case raises BadCredentialsException.

Previously, PullRequest.is_merged() used raw requestJson() which silently
returned False for any non-204 status code, including 401 (bad credentials)
and 403 (forbidden). This caused false negatives where an expired or invalid
authentication token would cause is_merged() to return False instead of
raising an appropriate exception.

Now is_merged() explicitly handles:
- 204: returns True (PR is merged)
- 404: returns False (PR is not merged)
- Any other status: raises the appropriate GithubException (e.g.
  BadCredentialsException for 401)

This brings is_merged() in line with the behavior of other PyGithub methods
that use requestJsonAndCheck() and properly surface authentication errors.

Fixes PyGithub#2760

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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.

Methods checking for 204 status handle 404 incorrectly

1 participant