MEDIUM SEVERITYCONFIRMED
model_copy() is shallow by default — mutating copy mutates original
Package
pydantic
Version
2.12.5
Verified
2026-03-28
Description
pydantic's `model_copy()` performs a shallow copy by default. Mutable fields (lists, dicts) are shared between the original and the copy. Appending to a list field on the copy also mutates the original model.
Reproduction
# m1 = MyModel(tags=[1, 2])
# m2 = m1.model_copy()
# m2.tags.append(99)
# assert m1.tags == [1, 2, 99] # True — original mutated