fix: handle missing content-length header in _get_tokenizer_config_size#763
Open
fern-support wants to merge 1 commit intomainfrom
Open
fix: handle missing content-length header in _get_tokenizer_config_size#763fern-support wants to merge 1 commit intomainfrom
fern-support wants to merge 1 commit intomainfrom
Conversation
When a server uses chunked transfer encoding, neither content-length nor x-goog-stored-content-length headers are present, leaving size as None. The subsequent int() cast then raises a TypeError. Add an explicit None check that raises a ValueError instead, which is caught gracefully by the existing try/except in both callers (get_hf_tokenizer and async_get_hf_tokenizer) — tokenizer download proceeds normally. Fixes: #762
02aa9f9 to
f9b1fd1
Compare
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
_get_tokenizer_config_sizeassumescontent-lengthorx-goog-stored-content-lengthheaders are always present, but servers using chunked transfer encoding omit both, leavingsizeasNoneint(None)then raises aTypeErrorFix
Add an explicit
Nonecheck that raises aValueErrorbefore theint()cast. Both callers already wrap this function intry/except Exceptionwith "Skip the size logging, this is not critical" — theValueErroris caught and the tokenizer download proceeds normally.Closes #762
Note
Low Risk
Low risk: adds a simple guard in non-critical size-logging code to avoid a
TypeErrorwhen servers omitContent-Lengthheaders (e.g., chunked transfer).Overview
Prevents
_get_tokenizer_config_sizefrom callingint(None)when tokenizer config HEAD responses omitContent-Length/x-goog-stored-content-lengthby explicitly raising aValueError.Callers already treat this as best-effort logging, so tokenizer downloads proceed while size logging is skipped when the header is missing.
Reviewed by Cursor Bugbot for commit f9b1fd1. Bugbot is set up for automated code reviews on this repo. Configure here.