﻿# Kedro MemoryDataset: assign mode can expose a branch to another node’s in-place changes

Choose Kedro MemoryDataset copy semantics deliberately when pipeline branches share mutable tables or model objects, testing whether node-side mutation reaches another consumer.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-kedro-memory-dataset-assign-branch-mutation/
Language: en

## Identify the object shared between branches

A preprocessing pipeline sends the same feature table to training and diagnostics. A diagnostic node adds a column in place, and a later training step unexpectedly sees it. The [MemoryDataset API](https://docs.kedro.org/en/stable/api/io/kedro.io.MemoryDataset/) supports deepcopy, copy and assign modes, with inference when a mode is omitted. The dataset name identifies a pipeline value, but its name alone says nothing about the ownership of the mutable Python object returned to each consumer.

## Treat assign as a deliberate aliasing decision

Assign mode retains object identity rather than providing an independent copy. This can be appropriate for objects that should be shared or cannot sensibly be duplicated. It also means an in-place operation can affect another holder of that object. The [Python copying guide](https://docs.python.org/3/library/copy.html) distinguishes bindings from copies and shallow from deep copying. Use that model to reason about nested mutable members instead of assuming a new outer table or wrapper guarantees independence of every contained value.

## Keep node behavior consistent with the ownership contract

A node that returns a transformed value without modifying its input has a different sharing risk from one that mutates the input before returning. Document that distinction where branches intentionally consume a common object. If isolation is required, select an appropriate copy policy or construct the independent value explicitly. Avoid assuming the broadest copy mode is universally suitable: model instances, device resources and external handles can require an application-specific lifetime rather than arbitrary duplication.

## Separate in-memory lifetime from durable evidence

The [Data Catalog reference](https://docs.kedro.org/en/stable/api/io/kedro.io.DataCatalog/) organizes dataset access, while MemoryDataset is ephemeral storage. A correctly isolated intermediate value is not automatically persisted for another worker or a later run. Decide independently whether the value needs a durable representation. This distinction prevents a fix for branch mutation from being overstated as reproducible storage of the intermediate dataset or the trained model that happened to reside in memory during execution.

## Probe mutation with a recognizable fixture

Use a small mutable object, load it for separate consumers and mutate a recognizable field through one consumer. Inspect the other under the intended copy policy, including any nested mutable members. Related guides explain [explicit table schemas](/journal/data-guide-frictionless-table-schema/) and [tensor memory descriptors](/journal/learn-tensor-memory-descriptor/). The fixture establishes ownership at the catalog boundary. A pipeline graph that shows distinct nodes remains compatible with shared object state unless the actual data-access and node-mutation contracts provide the intended separation.
