﻿# Prefect transaction values require an explicit set after mutation

Prefect transaction get returns a copy and can inherit a parent’s value; changing a returned list does not update stored transaction state until an explicit set.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-prefect-transaction-values-copy/
Language: en

## Read the list update as separate operations

An agent workflow stores a list of processed source identifiers in a transaction, retrieves it and appends another identifier. The [current transaction source](https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/transactions.py) deep-copies values returned by `get`. The retrieved list can change while the stored list remains as before. A later lookup may therefore appear to lose progress even though the local variable clearly contains the appended identifier.

## Write the changed value explicitly

The documented pattern reads the value, changes the local copy and calls `set` with the updated value. This makes the transaction update intentional rather than relying on mutation through a shared reference. For a processed-source list, keep the update close to the event it records. A local append proves only that the local object changed; the explicit write establishes what a subsequent transaction lookup should see.

## Understand inherited values and child overrides

When a value is not found locally, the implementation can look through the parent transaction. A child value with the same name shadows the parent's value. Because reads return copies, modifying a child-retrieved collection does not automatically mutate a parent's stored collection. Decide whether progress belongs to the child or should be deliberately published to the parent. Avoid assuming that nested context alone provides automatic shared mutable state for every named value.

## Separate context values from result commit

The [transaction reference](https://reference.prefect.io/prefect/transactions/) also exposes staging and commit operations. Named runtime values manipulated through `get` and `set` should not be casually described as a committed result record. The [cache-policy source](https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/cache_policies.py) separately defines identity used for record lookup. Keep the progress variable, transaction key and staged output distinct in the design. Changing a local value does not independently prove an external artifact was written or committed.

## Make progress ownership inspectable

Use clear names for child-local notes and the parent-level progress that downstream work expects. Read back the intended stored value after an explicit update, then inspect the relevant committed artifact when that is the actual completion condition. [Task contracts](/journal/learn-codex-task-contract/) state the deliverable; [tool observations](/journal/learn-codex-tool-observation/) distinguish in-memory manipulation and persisted effects. This gives a reader a concrete explanation for where progress lives instead of treating every object visible in a transaction as one shared record.
