Skip to content

fix: return empty tuple from import_protobuf_decode_error when protobuf is unavailable#45486

Merged
ArthurZucker merged 2 commits intohuggingface:mainfrom
jw9603:fix/protobuf-decode-error-masking
Apr 20, 2026
Merged

fix: return empty tuple from import_protobuf_decode_error when protobuf is unavailable#45486
ArthurZucker merged 2 commits intohuggingface:mainfrom
jw9603:fix/protobuf-decode-error-masking

Conversation

@jw9603
Copy link
Copy Markdown
Contributor

@jw9603 jw9603 commented Apr 16, 2026

Fixes #45459

What does this PR do?

import_protobuf_decode_error() raised ImportError when protobuf
was not installed. Python evaluates the except-class expression lazily,
so that ImportError replaced whatever the tokenizer constructor
actually raised. The RuntimeError and OSError handlers below never
ran either.

Changed the helper to return () when protobuf is unavailable so the
except clause matches nothing and the real exception propagates.
DecodeError catching when protobuf is installed is unchanged.

Not a duplicate of #45460 (closed; drops DecodeError catching) or #45466 (opened without issue-author approval).

Tests run:

$ python -m pytest tests/tokenization/test_tokenization_utils.py -v
19 passed, 1 skipped in 36.34s

Two new tests:

  • test_import_protobuf_decode_error_without_protobuf
  • test_import_protobuf_decode_error_does_not_mask_exceptions

Code Agent Policy

  • I confirm that this is not a pure code agent PR.

AI assistance (Claude) was used during investigation and patch
preparation. All changes were reviewed and tested by me.

Before submitting

Who can review?

@itazap @ArthurZucker

jw9603 and others added 2 commits April 16, 2026 23:24
…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
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty

@ArthurZucker ArthurZucker added this pull request to the merge queue Apr 20, 2026
Merged via the queue into huggingface:main with commit c3ec5ff Apr 20, 2026
28 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

except import_protobuf_decode_error() hides real tokenizer errors when protobuf isn't installed

4 participants