fix: raise exception in is_merged() for non-204/non-404 status codes#3466
Open
Aliipou wants to merge 1 commit intoPyGithub:mainfrom
Open
fix: raise exception in is_merged() for non-204/non-404 status codes#3466Aliipou wants to merge 1 commit intoPyGithub:mainfrom
Aliipou wants to merge 1 commit intoPyGithub:mainfrom
Conversation
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 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2760
PullRequest.is_merged()previously used rawrequestJson()which silently returnedFalsefor any non-204 status code, including:401 Bad credentials(expired/invalid token)403 ForbiddenThis caused false negatives where an expired authentication token would cause
is_merged()to returnFalseinstead of raising the appropriate exception, differing from all other PyGithub methods.Changes
The method now explicitly handles each case:
True(PR is merged)False(PR is not merged)GithubExceptionA test with replay data is included to verify the 401 case raises
BadCredentialsException.