Skip to content

Commit

Permalink
feature/#2330 Refactor the _check_required_properties function (#2422)
Browse files Browse the repository at this point in the history
Refactor the _check_required_properties function
  • Loading branch information
toan-quach authored Jan 28, 2025
1 parent 5f84c83 commit 60556b9
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions taipy/core/config/checkers/_data_node_config_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,11 @@ def _check_validity_period(self, data_node_config_id: str, data_node_config: Dat
f" None or populated with a timedelta value.",
)

def _check_required_properties(self, data_node_config_id: str, data_node_config: DataNodeConfig):
storage_type = data_node_config.storage_type
if not storage_type or storage_type not in DataNodeConfig._REQUIRED_PROPERTIES:
return

required_properties = DataNodeConfig._REQUIRED_PROPERTIES[storage_type]
@staticmethod
def __get_sql_required_properties(storage_type: str, dn_config_properties: Dict) -> List:
if storage_type == DataNodeConfig._STORAGE_TYPE_VALUE_SQL:
if data_node_config.properties:
if engine := data_node_config.properties.get(DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY):
if dn_config_properties:
if engine := dn_config_properties.get(DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY):
if engine == DataNodeConfig._DB_ENGINE_SQLITE:
required_properties = [
DataNodeConfig._REQUIRED_DB_NAME_SQL_PROPERTY,
Expand All @@ -126,9 +122,10 @@ def _check_required_properties(self, data_node_config_id: str, data_node_config:
DataNodeConfig._REQUIRED_READ_QUERY_SQL_PROPERTY,
DataNodeConfig._REQUIRED_WRITE_QUERY_BUILDER_SQL_PROPERTY,
]
return required_properties
if storage_type == DataNodeConfig._STORAGE_TYPE_VALUE_SQL_TABLE:
if data_node_config.properties:
if engine := data_node_config.properties.get(DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY):
if dn_config_properties:
if engine := dn_config_properties.get(DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY):
if engine == DataNodeConfig._DB_ENGINE_SQLITE:
required_properties = [
DataNodeConfig._REQUIRED_DB_NAME_SQL_PROPERTY,
Expand All @@ -143,7 +140,25 @@ def _check_required_properties(self, data_node_config_id: str, data_node_config:
DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY,
DataNodeConfig._REQUIRED_TABLE_NAME_SQL_TABLE_PROPERTY,
]
for required_property in required_properties:
return required_properties
return []

def __storage_type_specific_required_properties(self, storage_type: str, dn_config_properties: Dict) -> List:
if storage_type in (DataNodeConfig._STORAGE_TYPE_VALUE_SQL_TABLE, DataNodeConfig._STORAGE_TYPE_VALUE_SQL):
return self.__get_sql_required_properties(storage_type, dn_config_properties)
return []

def _check_required_properties(self, data_node_config_id: str, data_node_config: DataNodeConfig):
storage_type = data_node_config.storage_type
if not storage_type or storage_type not in DataNodeConfig._REQUIRED_PROPERTIES:
return

required_properties = DataNodeConfig._REQUIRED_PROPERTIES[storage_type]
required_properties.extend(
self.__storage_type_specific_required_properties(storage_type, data_node_config.properties)
)

for required_property in set(required_properties):
if not data_node_config.properties or required_property not in data_node_config.properties:
if data_node_config_id == DataNodeConfig._DEFAULT_KEY:
self._warning(
Expand Down

0 comments on commit 60556b9

Please sign in to comment.