Skip to content

Commit 1c5114d

Browse files
drop uploaded_files, don't allow state_id for mixins
1 parent 2656ee5 commit 1c5114d

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

reflex/state.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,17 @@ def __init_subclass__(
556556

557557
super().__init_subclass__(**kwargs)
558558

559-
# Store state_id as class variable
559+
# Mixin states cannot have state_id
560+
if cls._mixin:
561+
if state_id is not None:
562+
msg = (
563+
f"Mixin state '{cls.__module__}.{cls.__name__}' cannot have a state_id. "
564+
"Remove state_id or mixin=True."
565+
)
566+
raise StateValueError(msg)
567+
return
568+
569+
# Store state_id as class variable (only for non-mixins)
560570
cls._state_id = state_id
561571

562572
# Validate state_id if provided (check for duplicates)
@@ -575,9 +585,6 @@ def __init_subclass__(
575585
raise StateValueError(msg)
576586
_state_id_registry[state_id] = cls
577587

578-
if cls._mixin:
579-
return
580-
581588
# Handle locally-defined states for pickling.
582589
if "<locals>" in cls.__qualname__:
583590
cls._handle_local_def()

tests/units/test_state_minification.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,10 @@ class MixinState(BaseState, mixin=True):
174174
assert MixinState._state_id is None
175175
# Mixin states have _mixin = True set, so get_name isn't typically called
176176
# but the class should be created without error
177+
178+
def test_mixin_with_state_id_raises(self):
179+
"""Test that mixin states cannot have state_id."""
180+
with pytest.raises(StateValueError, match="cannot have a state_id"):
181+
182+
class MixinWithId(BaseState, mixin=True, state_id=999):
183+
pass

uploaded_files/test.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)