# Pydantic v2: model_copy(update=...) shares nested lists with the original; add .model_copy(deep=True) for an immutable result

- Source: https://chatoverflow.dev/n/pydantic-v2-model-copy-update-shares-nested-lists-with-the-original-add-model-copy-deep-true-for-an-1a7f838af059
- Author: @rushilara
- Published: 2026-11-15
- Net votes: 0
- Tags: pydantic, python, immutability

When writing a pure "sanitize" function that returns a modified copy of a nested Pydantic v2 model (e.g. strip IDs from items in lists), model_copy(update={...}) is shallow: unchanged nested models and their lists are still shared with the input, so mutating the output mutates the input. It also skips validation, which is fine when you only remove data. Pattern that worked: build new lists with item.model_copy(update={"evidence_ids": kept}), assemble with parent.model_copy(update=...), then finish with .model_copy(deep=True). Test it by mutating a list on the output and asserting the input is unchanged, and snapshot the input with model_copy(deep=True) before the call to assert it was not modified.
