@@ -1418,7 +1418,9 @@ class EntityData(dict):
14181418 """
14191419 def __init__ (self , * args , ** kwargs ) -> None :
14201420 super ().__init__ (* args , ** kwargs )
1421- self ._orig_data = copy .deepcopy (self )
1421+ self ._orig_data = {}
1422+ # Fill orig data
1423+ self .lock ()
14221424
14231425 def get_changes (self ) -> dict [str , Any ]:
14241426 """Changes in entity data.
@@ -1437,10 +1439,10 @@ def get_changes(self) -> dict[str, Any]:
14371439 output [key ] = None
14381440 elif key not in self ._orig_data :
14391441 # New value was set
1440- output [key ] = self [key ]
1442+ output [key ] = copy . deepcopy ( self [key ])
14411443 elif self [key ] != self ._orig_data [key ]:
14421444 # Value was changed
1443- output [key ] = self [key ]
1445+ output [key ] = copy . deepcopy ( self [key ])
14441446 return output
14451447
14461448 def get_new_entity_value (self ) -> dict [str , AttributeValueType ]:
@@ -1460,7 +1462,25 @@ def get_new_entity_value(self) -> dict[str, AttributeValueType]:
14601462 def lock (self ) -> None :
14611463 """Lock changes of entity data."""
14621464
1463- self ._orig_data = copy .deepcopy (self )
1465+ orig_data = {}
1466+ for key , value in self .items ():
1467+ try :
1468+ key = copy .deepcopy (key )
1469+ except RecursionError :
1470+ raise RuntimeError (
1471+ f"Failed to create copy of key '{ key } '"
1472+ " because of recursion."
1473+ )
1474+
1475+ try :
1476+ orig_data [key ] = copy .deepcopy (value )
1477+ except RecursionError :
1478+ raise RuntimeError (
1479+ f"Failed to create copy of value '{ key } '"
1480+ " because of recursion."
1481+ )
1482+
1483+ self ._orig_data = orig_data
14641484
14651485
14661486class BaseEntity (ABC ):
0 commit comments