forked from platypush/platypush
Added recursive .copy()
method to Entity
.
This commit is contained in:
parent
9f9ee575f1
commit
7e92d5f244
1 changed files with 11 additions and 0 deletions
|
@ -115,6 +115,17 @@ if 'entity' not in Base.metadata:
|
||||||
"""
|
"""
|
||||||
return str(self.external_id), str(self.plugin)
|
return str(self.external_id), str(self.plugin)
|
||||||
|
|
||||||
|
def copy(self) -> 'Entity':
|
||||||
|
"""
|
||||||
|
This method returns a copy of the entity. It's useful when you want
|
||||||
|
to reuse entity objects in other threads or outside of their
|
||||||
|
associated SQLAlchemy session context.
|
||||||
|
"""
|
||||||
|
return self.__class__(
|
||||||
|
**{col.key: getattr(self, col.key, None) for col in self.columns},
|
||||||
|
children=[child.copy() for child in self.children],
|
||||||
|
)
|
||||||
|
|
||||||
def _serialize_value(self, col: ColumnProperty) -> Any:
|
def _serialize_value(self, col: ColumnProperty) -> Any:
|
||||||
val = getattr(self, col.key)
|
val = getattr(self, col.key)
|
||||||
if isinstance(val, datetime):
|
if isinstance(val, datetime):
|
||||||
|
|
Loading…
Reference in a new issue