Fix: Handle /releases/tags/{tag} URL conversion to canonical form#3468
Closed
SebastienSyd wants to merge 2 commits intoPyGithub:mainfrom
Closed
Fix: Handle /releases/tags/{tag} URL conversion to canonical form#3468SebastienSyd wants to merge 2 commits intoPyGithub:mainfrom
SebastienSyd wants to merge 2 commits intoPyGithub:mainfrom
Conversation
When a release is fetched by tag name using repo.get_release('v1.0'),
the URL was set to /releases/tags/TAG_NAME instead of /releases/ID,
which caused subsequent API calls like get_assets() to fail with 404.
This fix updates __postProcess() in Requester.py to detect when:
1. The response contains an 'id' field
2. The URL contains '/tags/' (GitHub's name-based lookup pattern)
In these cases, it reconstructs the URL with the canonical ID-based form.
Also added a test case testGetAssetsByTag() to verify the fix.
Fixes PyGithub#3467
The test requires replay data to simulate API responses without making real API calls during testing.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3468 +/- ##
==========================================
+ Coverage 97.00% 97.05% +0.04%
==========================================
Files 172 176 +4
Lines 18934 19797 +863
==========================================
+ Hits 18366 19213 +847
- Misses 568 584 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
EnricoMi
reviewed
Mar 24, 2026
Collaborator
EnricoMi
left a comment
There was a problem hiding this comment.
I think the problem is not Requester reusing the URL here, but Release using the release-by-tag URL as the lazy URL in the first place.
| data["url"] = href | ||
| else: | ||
| data["url"] = url | ||
| # GitHub API provides name-based lookup shortcuts (e.g., /releases/tags/{tag}) |
Collaborator
There was a problem hiding this comment.
This is very class-specific logic in a very general place.
| self.assertTrue(asset is not None) | ||
| self.assertEqual(asset.id, asset_id) | ||
|
|
||
| def testGetAssetsByTag(self): |
Collaborator
There was a problem hiding this comment.
This test does not reproduce the issue. It already passes without your code changes in Requester.py.
EnricoMi
added a commit
that referenced
this pull request
Mar 24, 2026
Getting a release by tag cannot return a lazy release. The URL that is used to fetch the release by tag cannot be used for subsequent requests (like getting assets). The URL first has to be turned into the URL that contains the release id. This requires an API call. Supersedes #3468. Fixes #3467. Co-authored-by: Sebastien NICOT <[email protected]>
Collaborator
|
Closing in favour of #3469. |
Copilot AI
pushed a commit
that referenced
this pull request
Mar 26, 2026
Getting a release by tag cannot return a lazy release. The URL that is used to fetch the release by tag cannot be used for subsequent requests (like getting assets). The URL first has to be turned into the URL that contains the release id. This requires an API call. Supersedes #3468. Fixes #3467. Co-authored-by: Sebastien NICOT <[email protected]> Co-authored-by: EnricoMi <[email protected]>
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.
Description
Fixes #3467
When a release is fetched by tag name using
repo.get_release("v1.0"), the URL was incorrectly set to/releases/tags/TAG_NAMEinstead of/releases/ID, which caused subsequent API calls likeget_assets()to fail with a 404 error.Root Cause
The issue was introduced in v2.9.0 with lazy loading for releases (PR #3403). The
__postProcess()method inRequester.pywas setting the object's URL to the GET request URL when the response didn't contain aurlfield. For tag-based lookups (/releases/tags/{tag}), this resulted in a non-canonical URL being stored.Solution
Updated
__postProcess()inRequester.pyto:idfield AND the URL contains/tags/(GitHub's name-based lookup pattern)/releases/{id}This approach handles GitHub's API pattern for name-based lookups generically.
Changes
/tags/with the canonical ID-based formtestGetAssetsByTag()to verify releases fetched by tag can retrieve assets without 404 errorsTesting
The new test
testGetAssetsByTag()validates that:Impact