Fix #2806: NameError: name 'ClusterBackend' is not defined#2818
Fix #2806: NameError: name 'ClusterBackend' is not defined#2818danielalanbates wants to merge 1 commit intomodelscope:mainfrom
Conversation
…error message Replace bare except/pass with proper fallback initialization and a warning log when speaker-related modules fail to import. At the usage site, raise an informative ImportError instead of a cryptic NameError so users understand which dependency is missing.
Summary of ChangesHello @danielalanbates, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the stability and user experience of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes a NameError for ClusterBackend by initializing it to None before a try-except block that handles its import. This is a good approach. The PR also improves error handling by replacing a bare except with except Exception as e and logging a warning, and by adding a check to fail early if ClusterBackend could not be imported.
My review includes one suggestion to make the error handling even more robust by checking all related modules that are imported within the same try-except block, not just ClusterBackend. This will prevent potential TypeErrors at runtime and provide a consistent early-failure mechanism for missing speaker diarization dependencies.
| if ClusterBackend is None: | ||
| raise ImportError( | ||
| "ClusterBackend is not available. This is likely because required dependencies " | ||
| "(e.g. scikit-learn with HDBSCAN support, scipy) failed to import. " | ||
| "Please ensure scikit-learn>=1.3.0 and scipy are properly installed." | ||
| ) |
There was a problem hiding this comment.
While adding a check for ClusterBackend is a great improvement to fail early and provide a clear error message, the other modules imported in the same try-except block (sv_chunk, postprocess, distribute_spk) are not checked.
If their import fails, they will also be None, and calling them later in inference_with_vad will result in a TypeError: 'NoneType' object is not callable.
To make the error handling more robust, I suggest checking for all these modules at once. This ensures that if any of the speaker-related dependencies are missing, the program fails early with a clear error message.
if any(x is None for x in (sv_chunk, postprocess, distribute_spk, ClusterBackend)):
raise ImportError("Speaker diarization dependencies failed to import. Check logs and ensure optional packages are installed (e.g., scikit-learn, scipy).")
Fixes #2806
Summary
This PR addresses: NameError: name 'ClusterBackend' is not defined
Changes
Testing
Please review the changes carefully. The fix was verified against the existing test suite.
This PR was created with the assistance of Claude Sonnet 4.6 by Anthropic | effort: low. Happy to make any adjustments!