-
Notifications
You must be signed in to change notification settings - Fork 19k
Description
Checked other resources
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Example Code
from langchain_core.runnables.config import set_config_context
from langchain_core.runnables import RunnableConfig
# Test context manager protocol violations
config = RunnableConfig(enabled=True)
# Test entering twice
ctx_manager = set_config_context(config)
with ctx_manager as ctx1:
print("First enter")
try:
with ctx_manager as ctx2:
print("Second enter")
assert False, "Should raise RuntimeError"
except RuntimeError:
print("Caught expected RuntimeError on double enter")
# Test exiting without entering
try:
ctx_manager.__exit__(None, None, None)
assert False, "Should raise RuntimeError"
except RuntimeError:
print("Caught expected RuntimeError on exit without enter")
Error Message and Stack Trace (if applicable)
First enter
Traceback (most recent call last):
File "test_case.py", line 13, in <module>
with ctx_manager as ctx2:
File ".../lib/python3.10/contextlib.py", line 133, in __enter__
del self.args, self.kwds, self.func
AttributeError: args
Description
-
I'm trying to test the behavior of the
set_config_context
context manager inlangchain_core.runnables.config
. -
I expect it to raise a
RuntimeError
or give a clear error when trying to enter the context manager twice or exit without entering. -
Instead, entering the same context manager twice raises a non-obvious
AttributeError: args
, coming from Python'scontextlib.py
.
This is confusing and not safe for user code, since it violates context manager protocol silently and crashes due to internals of contextlib
.
System Info
System Information
OS: Linux
OS Version: #107-Ubuntu SMP Wed Feb 7 13:26:48 UTC 2024
Python Version: 3.10.16 (main, Dec 11 2024, 16:24:50) [GCC 11.2.0]
Package Information
langchain_core: 0.3.50
langchain: 0.3.22
langchain_community: 0.3.13
langsmith: 0.3.23
langchain_anthropic: 0.3.1
langchain_aws: 0.2.2
langchain_chroma: 0.2.0
langchain_experimental: 0.3.2
langchain_fireworks: 0.2.6
langchain_google_vertexai: 2.0.5
langchain_groq: 0.2.2
langchain_mistralai: 0.2.4
langchain_openai: 0.2.14
langchain_text_splitters: 0.3.7
langchain_together: 0.2.0
langchain_unstructured: 0.1.5
langgraph_sdk: 0.1.34
Optional packages not installed
langserve
Other Dependencies
aiohttp: 3.10.10
anthropic: 0.40.0
anthropic[vertexai]: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
boto3: 1.35.42
chromadb: 0.5.15
dataclasses-json: 0.6.7
defusedxml: 0.7.1
fastapi: 0.115.3
fireworks-ai: 0.15.7
google-cloud-aiplatform: 1.70.0
google-cloud-storage: 2.18.2
groq: 0.11.0
httpx: 0.28.1
httpx-sse: 0.4.0
jsonpatch<2.0,>=1.33: Installed. No version info available.
langchain-anthropic;: Installed. No version info available.
langchain-aws;: Installed. No version info available.
langchain-azure-ai;: Installed. No version info available.
langchain-cohere;: Installed. No version info available.
langchain-community;: Installed. No version info available.
langchain-core<1.0.0,>=0.3.45: Installed. No version info available.
langchain-core<1.0.0,>=0.3.49: Installed. No version info available.
langchain-deepseek;: Installed. No version info available.
langchain-fireworks;: Installed. No version info available.
langchain-google-genai;: Installed. No version info available.
langchain-google-vertexai;: Installed. No version info available.
langchain-groq;: Installed. No version info available.
langchain-huggingface;: Installed. No version info available.
langchain-mistralai;: Installed. No version info available.
langchain-ollama;: Installed. No version info available.
langchain-openai;: Installed. No version info available.
langchain-text-splitters<1.0.0,>=0.3.7: Installed. No version info available.
langchain-together;: Installed. No version info available.
langchain-xai;: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith<0.4,>=0.1.125: Installed. No version info available.
langsmith<0.4,>=0.1.17: Installed. No version info available.
numpy: 1.26.4
openai: 1.57.4
openai-agents: Installed. No version info available.
opentelemetry-api: 1.27.0
opentelemetry-exporter-otlp-proto-http: Installed. No version info available.
opentelemetry-sdk: 1.27.0
orjson: 3.10.16
packaging: 24.1
packaging<25,>=23.2: Installed. No version info available.
pydantic: 2.11.1
pydantic-settings: 2.6.0
pydantic<3.0.0,>=2.5.2;: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic<3.0.0,>=2.7.4;: Installed. No version info available.
pytest: 8.3.4
PyYAML: 6.0.2
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.3
requests-toolbelt: 1.0.0
requests<3,>=2: Installed. No version info available.
rich: 13.9.3
SQLAlchemy: 2.0.40
SQLAlchemy<3,>=1.4: Installed. No version info available.
tenacity: 9.1.2
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tiktoken: 0.8.0
tokenizers: 0.21.0
typing-extensions>=4.7: Installed. No version info available.
unstructured-client: 0.25.9
unstructured[all-docs]: Installed. No version info available.
zstandard: 0.23.0