Skip to content

Commit 20efb30

Browse files
fix: make sure server event does not break when it has extra fields
1 parent cbc54e2 commit 20efb30

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

realtime_agent/realtime/struct.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,9 @@ def from_dict(data_class, data):
629629
"""Recursively convert a dictionary to a dataclass instance."""
630630
if is_dataclass(data_class): # Check if the target class is a dataclass
631631
fieldtypes = {f.name: f.type for f in data_class.__dataclass_fields__.values()}
632-
return data_class(**{f: from_dict(fieldtypes[f], data[f]) for f in data})
632+
# Filter out keys that are not in the dataclass fields
633+
valid_data = {f: data[f] for f in fieldtypes if f in data}
634+
return data_class(**{f: from_dict(fieldtypes[f], valid_data[f]) for f in valid_data})
633635
elif isinstance(data, list): # Handle lists of nested dataclass objects
634636
return [from_dict(data_class.__args__[0], item) for item in data]
635637
else: # For primitive types (str, int, float, etc.), return the value as-is

0 commit comments

Comments
 (0)