Fix boolean status methods to raise on error statuses instead of returning False by toroleapinc · Pull Request #3456 · PyGithub/PyGithub · GitHub
Skip to content

Fix boolean status methods to raise on error statuses instead of returning False#3456

Open
toroleapinc wants to merge 1 commit into
PyGithub:mainfrom
toroleapinc:fix/issue-2760-bool-status-check
Open

Fix boolean status methods to raise on error statuses instead of returning False#3456
toroleapinc wants to merge 1 commit into
PyGithub:mainfrom
toroleapinc:fix/issue-2760-bool-status-check

Conversation

@toroleapinc

Copy link
Copy Markdown

Problem

Methods like PullRequest.is_merged() use requestJson() and check status == 204 to return a boolean. This silently returns False for any non-204 status, including error statuses like:

  • 401 (expired/invalid token)
  • 403 (insufficient permissions)
  • 500 (server error)

This leads to false negatives — e.g. is_merged() returns False when the token has expired, even if the PR is actually merged.

Solution

Add Requester.requestJsonAndBoolCheck() that:

  1. Returns True for the expected status (204)
  2. Returns False for the absent status (404)
  3. Raises the appropriate GithubException for all other statuses

Updated PullRequest.is_merged() to use this method. Other methods using the same return status == 204 pattern can be migrated incrementally.

Fixes #2760

Add Requester.requestJsonAndBoolCheck() that correctly handles boolean
API endpoints (204/404). Instead of silently returning False for error
statuses like 401 (expired token) or 403 (no access), the new method
raises the appropriate GithubException, preventing false negatives.

Update PullRequest.is_merged() to use the new method as a first step.
Other methods using the same pattern (return status == 204) can be
migrated incrementally.

Fixes PyGithub#2760

Signed-off-by: edvatar <88481784+toroleapinc@users.noreply.github.com>
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