Skip to content

Commit 542ee70

Browse files
authored
fix missing value for mutable state field leading to shared field value (#5416)
1 parent d22034a commit 542ee70

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

reflex/vars/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,9 +3383,15 @@ def __init__(
33833383
type_origin = get_origin(annotated_type) or annotated_type
33843384

33853385
if self.default is MISSING and self.default_factory is None:
3386-
self.default = types.get_default_value_for_type(annotated_type)
3387-
if self.default is None and not types.is_optional(annotated_type):
3386+
default_value = types.get_default_value_for_type(annotated_type)
3387+
if default_value is None and not types.is_optional(annotated_type):
33883388
annotated_type = annotated_type | None
3389+
if types.is_immutable(default_value):
3390+
self.default = default_value
3391+
else:
3392+
self.default_factory = functools.partial(
3393+
copy.deepcopy, default_value
3394+
)
33893395
self.outer_type_ = self.annotated_type = annotated_type
33903396

33913397
if type_origin is Annotated:

0 commit comments

Comments
 (0)