You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gh pr view --json number returns exit 0 for Issue numbers due to numberFieldOnly optimization skipping API validation #13319
gh pr view <N> --json number returns {"number": N} with exit 0 even when N is an Issue number (not a PR). This makes it unreliable for scripts that use it to distinguish PRs from Issues.
Steps to Reproduce
# Replace 1099 with any Issue number in your repo (not a PR)
gh pr view 1099 --json number;echo"exit: $?"# Output:# {"number":1099}# exit: 0 ← wrong: this is an Issue, not a PR
# Adding any PR-specific field correctly fails
gh pr view 1099 --json number,headRefName;echo"exit: $?"# Output:# exit: 1 ← correct
Expected Behavior
gh pr view <N> --json number should return a non-zero exit code when N is not a PR.
Actual Behavior
Returns {"number": N} and exit 0 without hitting the API, regardless of whether N corresponds to a PR.
Root Cause
In pkg/cmd/pr/shared/finder.go, the numberFieldOnly optimization skips the API call entirely when only the number field is requested:
numberFieldOnly:=fields.Len() ==1&&fields.Contains("number")
iff.prNumber>0 {
ifnumberFieldOnly {
// avoid hitting the API if we already have all the informationreturn&api.PullRequest{Number: f.prNumber}, f.baseRefRepo, nil
}
pr, err=findByNumber(httpClient, f.baseRefRepo, f.prNumber, fields.ToSlice())
The issue is that f.prNumber is set simply by parsing the selector string as an integer — it does not confirm the number corresponds to an existing PR. The optimization conflates "we know the number" with "we know it's a PR with that number."
Impact
Any script using gh pr view <N> --json number to detect whether N is a PR will produce false positives for Issue numbers.
Good catch and thank you for reporting this with all the details we'd need, @apokamo! 🍻
The fix is merged and will be shipped with the next release.
Note for later viewers: in the meantime as mentioned in the issue description you can workaround this by adding a second field to the --json option, e.g.:
Activity
babakks commentedon May 2, 2026
Good catch and thank you for reporting this with all the details we'd need, @apokamo! 🍻
The fix is merged and will be shipped with the next release.
Note for later viewers: in the meantime as mentioned in the issue description you can workaround this by adding a second field to the
--jsonoption, e.g.: