Fix empty provider list from lazy langchain_community exports - #75
Open
enichols76work wants to merge 4 commits into
Open
Fix empty provider list from lazy langchain_community exports#75enichols76work wants to merge 4 commits into
enichols76work wants to merge 4 commits into
Conversation
get_langchain_chat_models_info() read chat_models_module.__dict__ directly, which bypasses langchain_community.chat_models' lazy __getattr__-based exports and always resolved to None. This left --list-providers, the interactive provider menus, and real ClientLangChain backend resolution all returning zero providers. Use getattr() so the lazy loader fires. This is a regression from 17f2502 ("Fix critical and high severity Dependabot vulnerabilities (prompt-security#70)"), which bumped langchain-community 0.0.7 -> 0.3.x to fix CVE-2025-68664. That upgrade correctly moved the import from langchain.chat_models to langchain_community.chat_models (chat models relocated in the 0.1+ reorg) but kept the old __dict__.get() lookup. langchain.chat_models used to import classes eagerly, but langchain_community.chat_models 0.3.x resolves them lazily via module-level __getattr__, so __dict__ no longer contains them. Provider discovery has silently returned zero providers since that commit, uncaught because tests/test_chat_clients.py mocks chat_models_info entirely and never exercised the real discovery function. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
If getattr() ever raises while lazily resolving a chat model class (e.g. a broken submodule import), the class is skipped rather than crashing the whole discovery pass. Log it at warning level so a silently missing provider is visible in the console and prompt-security-fuzzer.log, rather than swallowed entirely. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Add comments covering the why behind the fake lazy-loading module setup and the usage-site patch target, and assert len(models) == 1 (not just membership) since the fake module's __all__ only ever lists one name. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Every existing test in this file patches chat_models_info with a fake dict, so none of them would catch the module-level attribute (chat_clients.py:15) going empty again. Add an unmocked check that it's populated and contains well-known backends. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
MergerWaiting for CI and review to complete. Commit |
Author
|
Flagging for reviewers: #72 also fixes this same bug (empty provider list from
Both resolve the immediate bug; #72 is the bigger, more invasive change. Wanted to surface the overlap so we don't land both / duplicate review effort — happy to close this one in favor of #72 if that's the preferred direction, or keep this as the low-risk fix to land now with #72's broader changes considered separately. |
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.
User description
Summary
get_langchain_chat_models_info()readchat_models_module.__dict__.get(name)directly, which bypasseslangchain_community.chat_models's lazy__getattr__-based exports (PEP 562) — every class always resolved toNone, so provider discovery silently returned{}.--list-providers, the interactive TUI's Target/Attack LLM provider menus, and instantiating any real (non-test-mocked) LangChain backend viaClientLangChain.17f2502("Fix critical and high severity Dependabot vulnerabilities (Fix critical and high severity Dependabot vulnerabilities #70)"), which correctly bumpedlangchain-communityto fix CVE-2025-68664 and moved the import fromlangchain.chat_modelstolangchain_community.chat_models, but didn't account for the newer package's lazy-loading mechanism. Uncaught for ~5 months because the existing test suite mockschat_models_infoentirely and never exercised the real discovery function.getattr(chat_models_module, model_cls_name, None)so the lazy loader actually fires, wrapped in try/except so one broken lazy import can't crash the whole CLI at startup, with alogger.warningif that ever happens.Testing
tests/test_langchain_integration.py: a real-library regression test (now discovers 59 providers, was 0) and a synthetic test reproducing the exact lazy-__getattr__mechanism, decoupled fromlangchain_community's actual internals.tests/test_chat_clients.pyguarding the real (unmocked)chat_models_infomodule attribute, since every existing test there patches it with a fake dict.Test plan
pytest— full suite greenpython -m ps_fuzz.cli --list-providers— prints real provider names, not just the headerpython3 -c "from ps_fuzz.langchain_integration import get_langchain_chat_models_info; print(len(get_langchain_chat_models_info()))"— returns 59, was 0Generated description
Below is a concise technical summary of the changes proposed in this PR:
Fix provider discovery in
ps_fuzz.langchain_integrationsoClientLangChainand the CLI menus can enumerate real LangChain chat backends again. Add regression coverage for lazylangchain_community.chat_modelsexports and thechat_models_infowiring.getattr()so lazylangchain_community.chat_modelsexports are discovered instead of returning an empty provider list.Modified files (1)
Latest Contributors(0)
__getattr__exports, and the unmockedchat_models_infocache used byClientLangChain.Modified files (2)
Latest Contributors(0)