Skip to content

Commit

Permalink
core[patch[: add exceptions propagation test for astream_events v2 (l…
Browse files Browse the repository at this point in the history
…angchain-ai#23159)

**Description:** `astream_events(version="v2")` didn't propagate
exceptions in `langchain-core<=0.2.6`, fixed in the langchain-ai#22916. This PR adds
a unit test to check that exceptions are propagated upwards.

Co-authored-by: Sergey Kozlov <[email protected]>
  • Loading branch information
skozlovf and Sergey Kozlov authored Jun 19, 2024
1 parent 50484be commit 94452a9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions libs/core/tests/unit_tests/runnables/test_runnable_events_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
import sys
import uuid
from functools import partial
from itertools import cycle
from typing import (
Any,
Expand Down Expand Up @@ -346,6 +347,22 @@ def reverse(s: str) -> str:
]


async def test_event_stream_exception() -> None:
def step(name: str, err: Optional[str], val: str) -> str:
if err:
raise ValueError(err)
return val + name[-1]

chain = (
RunnableLambda(partial(step, "step1", None))
| RunnableLambda(partial(step, "step2", "ERR"))
| RunnableLambda(partial(step, "step3", None))
)

with pytest.raises(ValueError, match="ERR"):
await _collect_events(chain.astream_events("X", version="v2"))


async def test_event_stream_with_triple_lambda_test_filtering() -> None:
"""Test filtering based on tags / names"""

Expand Down

0 comments on commit 94452a9

Please sign in to comment.