fix: return empty tuple from import_protobuf_decode_error when protobuf is unavailable#45486
Merged
ArthurZucker merged 2 commits intohuggingface:mainfrom Apr 20, 2026
Merged
Conversation
…uf is unavailable Previously the helper raised ImportError when protobuf was not installed. Because Python evaluates the except-class expression lazily, that ImportError replaced whatever the tokenizer constructor actually raised, and the RuntimeError/OSError handlers below never ran either. Return () instead so the except clause matches nothing and the real exception propagates. Fixes huggingface#45459
|
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. |
lvliang-intel
pushed a commit
to lvliang-intel/transformers
that referenced
this pull request
Apr 21, 2026
…uf is unavailable (huggingface#45486) Previously the helper raised ImportError when protobuf was not installed. Because Python evaluates the except-class expression lazily, that ImportError replaced whatever the tokenizer constructor actually raised, and the RuntimeError/OSError handlers below never ran either. Return () instead so the except clause matches nothing and the real exception propagates. Fixes huggingface#45459 Co-authored-by: Ita Zaporozhets <31893021+itazap@users.noreply.github.com>
artem-spector
pushed a commit
to artem-spector/transformers
that referenced
this pull request
Apr 21, 2026
…uf is unavailable (huggingface#45486) Previously the helper raised ImportError when protobuf was not installed. Because Python evaluates the except-class expression lazily, that ImportError replaced whatever the tokenizer constructor actually raised, and the RuntimeError/OSError handlers below never ran either. Return () instead so the except clause matches nothing and the real exception propagates. Fixes huggingface#45459 Co-authored-by: Ita Zaporozhets <31893021+itazap@users.noreply.github.com>
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.
Fixes #45459
What does this PR do?
import_protobuf_decode_error()raisedImportErrorwhen protobufwas not installed. Python evaluates the except-class expression lazily,
so that
ImportErrorreplaced whatever the tokenizer constructoractually raised. The
RuntimeErrorandOSErrorhandlers below neverran either.
Changed the helper to return
()when protobuf is unavailable so theexcept clause matches nothing and the real exception propagates.
DecodeErrorcatching when protobuf is installed is unchanged.Not a duplicate of #45460 (closed; drops DecodeError catching) or #45466 (opened without issue-author approval).
Tests run:
Two new tests:
test_import_protobuf_decode_error_without_protobuftest_import_protobuf_decode_error_does_not_mask_exceptionsCode Agent Policy
AI assistance (Claude) was used during investigation and patch
preparation. All changes were reviewed and tested by me.
Before submitting
Pull Request section?
to it if that's the case. (
except import_protobuf_decode_error()hides real tokenizer errors when protobuf isn't installed #45459, approved by @itazap)Who can review?
@itazap @ArthurZucker