Repository navigation
fix: raise a clear error for dataclasses.field(...) state var defaults - #7308
Conversation
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
[Medium impact] The change reaches state class declarations across Reflex. The implementation has no new confirmed defects, but the existing requirement to compare complete error messages must be satisfied before merging. SummaryThe PR now rejects
Reviews (11) · Last reviewed commit: "Reject dataclasses.field(...) in state c..." · Reviewed by Greptile |
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Resolve conflicts with the BaseStateMeta field-handling refactor: port the dataclasses.field(...) unpacking into _unannotated_fields/_annotated_fields, drop the obsolete new_backend_vars change (machinery removed upstream), and update the tests to __fields__ assertions.
masenf
left a comment
There was a problem hiding this comment.
thanks for your contribution. one outstanding issue regarding mutable defaults in unannotated fields
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
|
Could a maintainer rerun the failed build jobs? Setup timed out downloading Plotly 7.1.0 from PyPI after three retries, before the minimum-dependency check ran. The build gate failed because of that setup failure. |
# Conflicts: # packages/reflex-base/src/reflex_base/vars/base.py
Convert each dataclasses.Field in the class namespace to rx.field(...) before fields are collected, so every existing path (annotated, unannotated, backend, inherited overrides) treats it like rx.field. Drop the separate type inference and the require_serializable flag for unannotated fields: an unannotated dataclasses.field now types its var exactly like rx.field does.
A dataclasses.field(...) state var default crashed at compile time with "cannot pickle 'mappingproxy' object". Raise a StateValueError when the class is defined instead, naming the var and pointing to rx.field(...), rather than supporting a second way to declare fields.
Closes #7017
A state var default of
dataclasses.field(...)kept thedataclasses.Fieldobject itself as the default value. Building the initial state then deep-copied that object and failed on its metadata mappingproxy, with no hint of which var caused it:Now
BaseStateMetaraises aStateValueErrorwhen the class is defined. The message names the var and points to the supported form:Reflex keeps one way to declare a field (
rx.field) instead of supporting a second one.Tests:
test_dataclasses_field_default_raisesintests/units/reflex_base/vars/test_base.py(frontend and backend names, with and without annotation) andtest_state_var_dataclasses_field_default_raisesintests/units/test_state.py. Both fail on main and pass with the fix.AI help: used for parts of this change.