mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-30 05:25:05 +02:00
fix(langgraph): read langgraph_api.__version__ for delta support
Use the version constant exported by `langgraph-api` instead of package metadata for the DeltaChannel API compatibility check. This keeps the check aligned with the API package itself while still avoiding a hard dependency when `langgraph-api` is absent. Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
This commit is contained in:
co-authored by
open-swe[bot] <open-swe@users.noreply.github.com>
parent
30d1571f73
commit
289b4d4d78
@@ -9,7 +9,7 @@ from collections.abc import Awaitable, Callable, Hashable, Mapping, Sequence
|
||||
from dataclasses import dataclass, is_dataclass
|
||||
from datetime import timedelta
|
||||
from functools import partial
|
||||
from importlib import metadata
|
||||
from importlib import import_module
|
||||
from inspect import isclass, isfunction, ismethod, signature
|
||||
from types import FunctionType
|
||||
from types import NoneType as NoneType
|
||||
@@ -133,8 +133,8 @@ def _check_delta_channel_api_support(channels: Mapping[str, Any]) -> None:
|
||||
if not any(isinstance(c, DeltaChannel) for c in channels.values()):
|
||||
return
|
||||
try:
|
||||
api_version = metadata.version("langgraph-api")
|
||||
except metadata.PackageNotFoundError:
|
||||
api_version = import_module("langgraph_api").__version__
|
||||
except ImportError:
|
||||
return
|
||||
if Version(api_version) < Version("0.10.0"):
|
||||
raise RuntimeError(
|
||||
|
||||
@@ -8,7 +8,9 @@ is skipped when `langgraph-api` is not installed (local execution).
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
from types import ModuleType
|
||||
from typing import Annotated
|
||||
|
||||
import pytest
|
||||
@@ -17,7 +19,6 @@ from typing_extensions import TypedDict
|
||||
from langgraph.channels.delta import DeltaChannel
|
||||
from langgraph.constants import START
|
||||
from langgraph.graph import StateGraph
|
||||
from langgraph.graph import state as state_module
|
||||
from langgraph.graph.message import _messages_delta_reducer
|
||||
|
||||
|
||||
@@ -41,17 +42,15 @@ def _delta_graph() -> StateGraph:
|
||||
|
||||
@pytest.fixture
|
||||
def api_version(monkeypatch: pytest.MonkeyPatch):
|
||||
"""Override the reported `langgraph-api` version (or simulate absence)."""
|
||||
"""Override the imported `langgraph_api.__version__` (or simulate absence)."""
|
||||
|
||||
def _set(version: str | None) -> None:
|
||||
def fake_version(name: str) -> str:
|
||||
if name == "langgraph-api":
|
||||
if version is None:
|
||||
raise state_module.metadata.PackageNotFoundError(name)
|
||||
return version
|
||||
return state_module.metadata.version(name)
|
||||
|
||||
monkeypatch.setattr(state_module.metadata, "version", fake_version)
|
||||
if version is None:
|
||||
monkeypatch.setitem(sys.modules, "langgraph_api", None)
|
||||
return
|
||||
module = ModuleType("langgraph_api")
|
||||
setattr(module, "__version__", version)
|
||||
monkeypatch.setitem(sys.modules, "langgraph_api", module)
|
||||
|
||||
return _set
|
||||
|
||||
|
||||
Reference in New Issue
Block a user