Repository navigation
[Download] Fix ResolvedRevision string value after pickle/copy - #4692
Merged
Merged
Conversation
`str` subclasses are rebuilt through `__new__` with only their string value, so unpickling passed the string value as `resolved` and let `initial` fall back to its default, silently turning the string value into "main".
hanouticelina
marked this pull request as ready for review
August 17, 2026 09:00
hanouticelina
commented
Aug 17, 2026
hanouticelina
left a comment
Collaborator
Author
There was a problem hiding this comment.
✔️ looks good!
3 tasks done
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Contributor
|
This PR has been shipped as part of the v1.28.0 release. |
Collaborator
|
thanks for fixing! |
This was referenced Aug 27, 2026
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 #4688.
ResolvedRevisionis astrsubclass, and pickle/copyrebuildstrsubclasses through__new__with only the string value. So unpickling called__new__(cls, "3.0bpw")— the string value landed in theresolvedslot,initialfell back toNone, and the (immutable) string value silently became"main". The__dict__restore afterwards put.initial/.resolvedback, which is whyrepr()still looked correct and this was easy to miss.Adding
__reduce__makes pickle andcopy/deepcopyrebuild via__new__(cls, resolved, initial).Impact
hf_hub_downloadandsnapshot_downloadwere unaffected since they read.resolved. Every otherHfApimethod uses the string value, so after a round-trip they silently operated onmain:before:
after:
Notes
__reduce__rather than__getnewargs__(as proposed in Fix ResolvedRevision silently becoming "main" after pickling #4689): the latter widensstr.__getnewargs__'s return type fromtuple[str]totuple[str, str | None], whichty check srcrejects as an invalid override.copy.copy/copy.deepcopy, for bothinitial="3.0bpw"andinitial=None. Protocols 0 and 1 were already fine — they reconstruct throughstr.__new__rather than the reduce protocol.🤖 Generated with Claude Code
Note
Cursor Bugbot is generating a summary for commit f61a575. Configure here.