Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Only pass Model.__fields__ when casting event args #4356

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from reflex.config import get_config
from reflex.istate.data import RouterData
from reflex.istate.storage import ClientStorageBase
from reflex.model import Model
from reflex.vars.base import (
ComputedVar,
DynamicRouteVar,
Expand Down Expand Up @@ -1733,15 +1734,20 @@ async def _process_event(
if value is None:
continue
hinted_args = value_inside_optional(hinted_args)
if (
isinstance(value, dict)
and inspect.isclass(hinted_args)
and (
dataclasses.is_dataclass(hinted_args)
or issubclass(hinted_args, Base)
)
):
payload[arg] = hinted_args(**value)
if isinstance(value, dict) and inspect.isclass(hinted_args):
if issubclass(hinted_args, Model):
# Remove non-fields from the payload
payload[arg] = hinted_args(
**{
key: value
for key, value in value.items()
if key in hinted_args.__fields__
}
)
elif dataclasses.is_dataclass(hinted_args) or issubclass(
hinted_args, Base
):
payload[arg] = hinted_args(**value)
if isinstance(value, list) and (hinted_args is set or hinted_args is Set):
payload[arg] = set(value)
if isinstance(value, list) and (
Expand Down
Loading