|
46 | 46 | from reflex.config import get_config |
47 | 47 | from reflex.istate.data import RouterData |
48 | 48 | from reflex.istate.storage import ClientStorageBase |
| 49 | +from reflex.model import Model |
49 | 50 | from reflex.vars.base import ( |
50 | 51 | ComputedVar, |
51 | 52 | DynamicRouteVar, |
@@ -1733,15 +1734,20 @@ async def _process_event( |
1733 | 1734 | if value is None: |
1734 | 1735 | continue |
1735 | 1736 | hinted_args = value_inside_optional(hinted_args) |
1736 | | - if ( |
1737 | | - isinstance(value, dict) |
1738 | | - and inspect.isclass(hinted_args) |
1739 | | - and ( |
1740 | | - dataclasses.is_dataclass(hinted_args) |
1741 | | - or issubclass(hinted_args, Base) |
1742 | | - ) |
1743 | | - ): |
1744 | | - payload[arg] = hinted_args(**value) |
| 1737 | + if isinstance(value, dict) and inspect.isclass(hinted_args): |
| 1738 | + if issubclass(hinted_args, Model): |
| 1739 | + # Remove non-fields from the payload |
| 1740 | + payload[arg] = hinted_args( |
| 1741 | + **{ |
| 1742 | + key: value |
| 1743 | + for key, value in value.items() |
| 1744 | + if key in hinted_args.__fields__ |
| 1745 | + } |
| 1746 | + ) |
| 1747 | + elif dataclasses.is_dataclass(hinted_args) or issubclass( |
| 1748 | + hinted_args, Base |
| 1749 | + ): |
| 1750 | + payload[arg] = hinted_args(**value) |
1745 | 1751 | if isinstance(value, list) and (hinted_args is set or hinted_args is Set): |
1746 | 1752 | payload[arg] = set(value) |
1747 | 1753 | if isinstance(value, list) and ( |
|
0 commit comments