Skip to content

0.46.0 - Breaking Change: store_factory

Choose a tag to compare

@mdrideout mdrideout released this 01 Jun 12:51

Breaking Change

This release fixes a bug which caused Subflow instances to share a global store singleton. A new store_factory pattern has been implemented to guarantee every Workflow and Subflow execution utilizes a fresh isolated store and state.

The following illustrates the breaking change for Workflow and Subflow Store and State creation.

Workflow Example

The store is no longer instantiated and passed to the Workflow. We now use store_factory and a lambda to pass a callable to the Workflow that will instantiate the store at .execute().

You may still pass initial store values this way.

-    # Create the store with initial state
-    store = CreateContactStore(
-        initial_state=CreateContactState(foo=bar)
-    )

    # Create the workflow
    create_contact_workflow = Workflow[CreateContactState, CreateContactStore](
        name="Create Contact Workflow",
        graph=create_contact_graph,
-      store=store,
+      store_factory=lambda: CreateContactStore(
+           initial_state=CreateContactState(foo=bar)
+       ),
        hook_manager=HookManager(verbose_logging=True, open_telemetry=True),
    )

Subflow Example

The Subflow now follows an identical pattern. Use store_factory with a lambda function to instantiate the store and state.

# SubFlow Test - Test Running A SubFlow
sub_flow_test = TestSubFlow(
    graph=test_sub_flow_graph,
-   store=TestSubFlowStore(initial_state=TestSubFlowState())
+   store_factory=lambda: TestSubFlowStore(initial_state=TestSubFlowState())
)

Full Changelog: 0.45.0...0.46.0