Skip to content

Commit d80ed96

Browse files
authored
Remove next() method from Graph (#2440)
1 parent 223a58f commit d80ed96

File tree

3 files changed

+4
-71
lines changed

3 files changed

+4
-71
lines changed

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Pydantic AI is still pre-version 1, so breaking changes will occur, however:
1212
!!! note
1313
Here's a filtered list of the breaking changes for each version to help you upgrade Pydantic AI.
1414

15+
### v0.6.0 (2025-08-06)
16+
17+
See [#2440](https://github.com/pydantic/pydantic-ai/pull/2440) - The `next` method was removed from the `Graph` class. Use `async with graph.iter(...) as run: run.next()` instead.
18+
1519
### v0.5.0 (2025-08-04)
1620

1721
See [#2388](https://github.com/pydantic/pydantic-ai/pull/2388) - The `source` field of an `EvaluationResult` is now of type `EvaluatorSpec` rather than the actual source `Evaluator` instance, to help with serialization/deserialization.

pydantic_graph/pydantic_graph/graph.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import logfire_api
1212
import typing_extensions
13-
from typing_extensions import deprecated
1413
from typing_inspection import typing_objects
1514

1615
from . import _utils, exceptions, mermaid
@@ -342,43 +341,6 @@ async def initialize(
342341
persistence.set_graph_types(self)
343342
await persistence.snapshot_node(state, node)
344343

345-
@deprecated('`next` is deprecated, use `async with graph.iter(...) as run: run.next()` instead')
346-
async def next(
347-
self,
348-
node: BaseNode[StateT, DepsT, RunEndT],
349-
persistence: BaseStatePersistence[StateT, RunEndT],
350-
*,
351-
state: StateT = None,
352-
deps: DepsT = None,
353-
infer_name: bool = True,
354-
) -> BaseNode[StateT, DepsT, Any] | End[RunEndT]:
355-
"""Run a node in the graph and return the next node to run.
356-
357-
Args:
358-
node: The node to run.
359-
persistence: State persistence interface, defaults to
360-
[`SimpleStatePersistence`][pydantic_graph.SimpleStatePersistence] if `None`.
361-
state: The current state of the graph.
362-
deps: The dependencies of the graph.
363-
infer_name: Whether to infer the graph name from the calling frame.
364-
365-
Returns:
366-
The next node to run or [`End`][pydantic_graph.nodes.End] if the graph has finished.
367-
"""
368-
if infer_name and self.name is None:
369-
self._infer_name(inspect.currentframe())
370-
371-
persistence.set_graph_types(self)
372-
run = GraphRun[StateT, DepsT, RunEndT](
373-
graph=self,
374-
start_node=node,
375-
persistence=persistence,
376-
state=state,
377-
deps=deps,
378-
traceparent=None,
379-
)
380-
return await run.next(node)
381-
382344
def mermaid_code(
383345
self,
384346
*,

tests/graph/test_graph.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -401,39 +401,6 @@ async def run(self, ctx: GraphRunContext) -> End[None]:
401401
await run.next()
402402

403403

404-
async def test_next(mock_snapshot_id: object):
405-
@dataclass
406-
class Foo(BaseNode):
407-
async def run(self, ctx: GraphRunContext) -> Bar:
408-
return Bar()
409-
410-
@dataclass
411-
class Bar(BaseNode):
412-
async def run(self, ctx: GraphRunContext) -> Foo:
413-
return Foo() # pragma: no cover
414-
415-
g = Graph(nodes=(Foo, Bar))
416-
assert g.name is None
417-
sp = FullStatePersistence()
418-
with pytest.warns(DeprecationWarning, match='`next` is deprecated, use `async with graph.iter(...)'):
419-
n = await g.next(Foo(), persistence=sp) # pyright: ignore[reportDeprecated]
420-
assert n == Bar()
421-
assert g.name == 'g'
422-
assert sp.history == snapshot(
423-
[
424-
NodeSnapshot(
425-
state=None,
426-
node=Foo(),
427-
start_ts=IsNow(tz=timezone.utc),
428-
duration=IsFloat(),
429-
status='success',
430-
id='Foo:1',
431-
),
432-
NodeSnapshot(state=None, node=Bar(), id='Bar:2'),
433-
]
434-
)
435-
436-
437404
async def test_deps(mock_snapshot_id: object):
438405
@dataclass
439406
class Deps:

0 commit comments

Comments
 (0)