Fix inverted assertion in remove_handler#46227
Merged
Rocketknight1 merged 1 commit intoMay 28, 2026
Merged
Conversation
The assert condition in remove_handler checks 'handler not in handlers', which raises AssertionError when removing a registered handler and silently passes for unregistered ones. Invert the condition to correctly validate that the handler exists before removal. Fixes huggingface#21506 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Rocketknight1
approved these changes
May 28, 2026
Member
Rocketknight1
left a comment
There was a problem hiding this comment.
Yeah this seems obviously correct. Not sure why it hasn't surfaced already, but I guess the path is just rarely used!
Rocketknight1
approved these changes
May 28, 2026
|
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. |
yuchenxie4645
pushed a commit
to yuchenxie4645/transformers
that referenced
this pull request
May 28, 2026
The assert condition in remove_handler checks 'handler not in handlers', which raises AssertionError when removing a registered handler and silently passes for unregistered ones. Invert the condition to correctly validate that the handler exists before removal. Fixes huggingface#21506 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
kashif
pushed a commit
to kashif/transformers
that referenced
this pull request
Jun 1, 2026
The assert condition in remove_handler checks 'handler not in handlers', which raises AssertionError when removing a registered handler and silently passes for unregistered ones. Invert the condition to correctly validate that the handler exists before removal. Fixes huggingface#21506 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
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.
What does this PR do?
Fixes an inverted assertion in
remove_handler()insrc/transformers/utils/logging.py.The current assert checks
handler not in _get_library_root_logger().handlers, which raisesAssertionErrorwhen callingremove_handlerwith a registered handler (the valid use case), while silently passing for unregistered handlers (the invalid use case). This one-word fix inverts the condition to correctly validate that the handler exists before removal.Bug introduced in: #10633 (2021-03-10)
Previously reported in: #21506 (never fixed)
Before
remove_handler(registered_handler)raisesAssertionErrorremove_handler(unknown_handler)passes silentlyAfter
remove_handler(registered_handler)succeedsremove_handler(unknown_handler)raisesAssertionErrorFixes #21506