diff --git a/taipy/core/data/_data_converter.py b/taipy/core/data/_data_converter.py index 10442e626e..d934d42497 100644 --- a/taipy/core/data/_data_converter.py +++ b/taipy/core/data/_data_converter.py @@ -12,6 +12,7 @@ from copy import copy from datetime import datetime, timedelta from pydoc import locate +from typing import Dict from .._repository._abstract_converter import _AbstractConverter from ..common._utils import _load_fct @@ -120,14 +121,13 @@ def __serialize_exposed_type(properties: dict, exposed_type_key: str, valid_str_ for v in properties[exposed_type_key] ] else: - properties[ - exposed_type_key - ] = f"{properties[exposed_type_key].__module__}.{properties[exposed_type_key].__qualname__}" + properties[exposed_type_key] = ( + f"{properties[exposed_type_key].__module__}.{properties[exposed_type_key].__qualname__}" + ) return properties @classmethod - def _entity_to_model(cls, data_node: DataNode) -> _DataNodeModel: - properties = data_node._properties.data.copy() + def _serialize_properties(cls, data_node: DataNode, properties: Dict) -> Dict: if data_node.storage_type() == GenericDataNode.storage_type(): properties = cls.__serialize_generic_dn_properties(properties) @@ -144,6 +144,11 @@ def _entity_to_model(cls, data_node: DataNode) -> _DataNodeModel: properties = cls.__serialize_exposed_type( properties, cls._EXPOSED_TYPE_KEY, cls._VALID_STRING_EXPOSED_TYPES ) + return properties + + @classmethod + def _entity_to_model(cls, data_node: DataNode) -> _DataNodeModel: + properties = cls._serialize_properties(data_node, data_node._properties.data.copy()) return _DataNodeModel( data_node.id, @@ -273,25 +278,28 @@ def __deserialize_exposed_type(properties: dict, exposed_type_key: str, valid_st return properties @classmethod - def _model_to_entity(cls, model: _DataNodeModel) -> DataNode: - data_node_properties = model.data_node_properties.copy() - + def _deserialize_properties(cls, model: _DataNodeModel, properties: Dict) -> Dict: if model.storage_type == GenericDataNode.storage_type(): - data_node_properties = cls.__deserialize_generic_dn_properties(data_node_properties) + properties = cls.__deserialize_generic_dn_properties(properties) if model.storage_type == JSONDataNode.storage_type(): - data_node_properties = cls.__deserialize_json_dn_properties(data_node_properties) + properties = cls.__deserialize_json_dn_properties(properties) if model.storage_type == SQLDataNode.storage_type(): - data_node_properties = cls.__deserialize_sql_dn_model_properties(data_node_properties) + properties = cls.__deserialize_sql_dn_model_properties(properties) if model.storage_type == MongoCollectionDataNode.storage_type(): - data_node_properties = cls.__deserialize_mongo_collection_dn_model_properties(data_node_properties) + properties = cls.__deserialize_mongo_collection_dn_model_properties(properties) - if cls._EXPOSED_TYPE_KEY in data_node_properties.keys(): - data_node_properties = cls.__deserialize_exposed_type( - data_node_properties, cls._EXPOSED_TYPE_KEY, cls._VALID_STRING_EXPOSED_TYPES + if cls._EXPOSED_TYPE_KEY in properties.keys(): + properties = cls.__deserialize_exposed_type( + properties, cls._EXPOSED_TYPE_KEY, cls._VALID_STRING_EXPOSED_TYPES ) + return properties + + @classmethod + def _model_to_entity(cls, model: _DataNodeModel) -> DataNode: + data_node_properties = cls._deserialize_properties(model, model.data_node_properties.copy()) validity_period = None if model.validity_seconds is not None and model.validity_days is not None: