Home / Function/ test_retry_batch_preserves_order() — langchain Function Reference

test_retry_batch_preserves_order() — langchain Function Reference

Architecture documentation for the test_retry_batch_preserves_order() function in test_runnable.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4b8272eb_38a4_8b7f_1979_8fbc0d8cb6f6["test_retry_batch_preserves_order()"]
  26df6ad8_0189_51d0_c3c1_6c3248893ff5["test_runnable.py"]
  4b8272eb_38a4_8b7f_1979_8fbc0d8cb6f6 -->|defined in| 26df6ad8_0189_51d0_c3c1_6c3248893ff5
  593bb72a_4695_6c93_b95c_e277aca006ae["batch()"]
  4b8272eb_38a4_8b7f_1979_8fbc0d8cb6f6 -->|calls| 593bb72a_4695_6c93_b95c_e277aca006ae
  style 4b8272eb_38a4_8b7f_1979_8fbc0d8cb6f6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/runnables/test_runnable.py lines 3930–3957

def test_retry_batch_preserves_order() -> None:
    """Regression test: batch with retry should preserve input order.

    The previous implementation stored successful results in a map keyed by the
    index within the *pending* (filtered) list rather than the original input
    index, causing collisions after retries. This produced duplicated outputs
    and dropped earlier successes (e.g. [0,1,2] -> [1,1,2]).
    """
    # Fail only the middle element on the first attempt to trigger the bug.
    first_fail: set[int] = {1}

    def sometimes_fail(x: int) -> int:  # pragma: no cover - trivial
        if x in first_fail:
            first_fail.remove(x)
            msg = "fail once"
            raise ValueError(msg)
        return x

    runnable = RunnableLambda(sometimes_fail)

    results = runnable.with_retry(
        stop_after_attempt=2,
        wait_exponential_jitter=False,
        retry_if_exception_type=(ValueError,),
    ).batch([0, 1, 2])

    # Expect exact ordering preserved.
    assert results == [0, 1, 2]

Domain

Subdomains

Calls

Frequently Asked Questions

What does test_retry_batch_preserves_order() do?
test_retry_batch_preserves_order() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_retry_batch_preserves_order() defined?
test_retry_batch_preserves_order() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 3930.
What does test_retry_batch_preserves_order() call?
test_retry_batch_preserves_order() calls 1 function(s): batch.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free