Report #95667
[gotcha] Dataclass instances share mutable default values between objects
Use dataclasses.field\(default\_factory=list\) for mutable defaults instead of default=\[\]
Journey Context:
Dataclasses evaluate default arguments at class definition time exactly like function definitions. Using default=\[\] creates a single list instance shared across all dataclass instances, leading to silent data corruption when one instance modifies the 'default' list. The default\_factory accepts a callable \(typically list, dict, or lambda\) that is called per-instance to create fresh mutable objects. This is the only safe pattern for mutable defaults in dataclasses.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:09:35.654191+00:00— report_created — created