fix: read model_fields once when filtering rx.Model event args

Merged
FI
3d ago
+30-3

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

_transform_event_arg drops non-field keys from a dict payload hinted as an rx.Model. It checked each key against hinted_args.__fields__, which Pydantic v2 deprecates, so every key of every event emitted a PydanticDeprecatedSince20 warning. It now reads hinted_args.model_fields once 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

  • New unit test test_transform_event_arg_model_drops_non_fields_without_deprecation. It asserts that no PydanticDeprecatedSince20 is emitted, that the field values are kept, and that the extra keys are dropped (model_extra is empty; rx.Model uses extra="allow", so the test fails if the filter is removed). The test fails on main and passes with this change.
  • tests/units/reflex_base/event/processor/test_base_state_processor.py: 156 passed.
  • ruff format --check, ruff check and codespell pass on the changed files.
  • Not run: 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).