Repository navigation
fix: read model_fields once when filtering rx.Model event args - #7636
Conversation
Event arguments hinted as an rx.Model dropped non-field payload keys by checking each key against `__fields__`, which Pydantic v2 deprecates, so every key emitted a PydanticDeprecatedSince20 warning on every event. Read `model_fields` once before filtering instead. Closes reflex-dev#7634
[Low impact] The PR appears safe to merge. SummaryReads
No actionable issues found. Tests were not run during this review. Reviews (1) · Last reviewed commit: "fix: read model_fields once when filteri..." · Reviewed by Greptile |
Merging this PR will degrade performance by 5.78%1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
All Submissions:
Type of change
Changes To Core Features:
Description
_transform_event_argdrops non-field keys from a dict payload hinted as anrx.Model. It checked each key againsthinted_args.__fields__, which Pydantic v2 deprecates, so every key of every event emitted aPydanticDeprecatedSince20warning. It now readshinted_args.model_fieldsonce before filtering. The filtering behaviour is unchanged.This touches a different call site than #7592, which covers
reflex_base/utils/types.py. The two PRs don't overlap.closes #7634
Verification
test_transform_event_arg_model_drops_non_fields_without_deprecation. It asserts that noPydanticDeprecatedSince20is emitted, that the field values are kept, and that the extra keys are dropped (model_extrais empty;rx.Modelusesextra="allow", so the test fails if the filter is removed). The test fails onmainand passes with this change.tests/units/reflex_base/event/processor/test_base_state_processor.py: 156 passed.ruff format --check,ruff checkandcodespellpass on the changed files.pyright,ty,biome, the integration tests and the full unit suite.A towncrier news fragment is included (
packages/reflex-base/news/+model-event-arg-fields.bugfix.md).