Skip to content

Commit 60556b9

Browse files
authored
feature/#2330 Refactor the _check_required_properties function (#2422)
Refactor the _check_required_properties function
1 parent 5f84c83 commit 60556b9

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

taipy/core/config/checkers/_data_node_config_checker.py

+26-11
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,11 @@ def _check_validity_period(self, data_node_config_id: str, data_node_config: Dat
101101
f" None or populated with a timedelta value.",
102102
)
103103

104-
def _check_required_properties(self, data_node_config_id: str, data_node_config: DataNodeConfig):
105-
storage_type = data_node_config.storage_type
106-
if not storage_type or storage_type not in DataNodeConfig._REQUIRED_PROPERTIES:
107-
return
108-
109-
required_properties = DataNodeConfig._REQUIRED_PROPERTIES[storage_type]
104+
@staticmethod
105+
def __get_sql_required_properties(storage_type: str, dn_config_properties: Dict) -> List:
110106
if storage_type == DataNodeConfig._STORAGE_TYPE_VALUE_SQL:
111-
if data_node_config.properties:
112-
if engine := data_node_config.properties.get(DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY):
107+
if dn_config_properties:
108+
if engine := dn_config_properties.get(DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY):
113109
if engine == DataNodeConfig._DB_ENGINE_SQLITE:
114110
required_properties = [
115111
DataNodeConfig._REQUIRED_DB_NAME_SQL_PROPERTY,
@@ -126,9 +122,10 @@ def _check_required_properties(self, data_node_config_id: str, data_node_config:
126122
DataNodeConfig._REQUIRED_READ_QUERY_SQL_PROPERTY,
127123
DataNodeConfig._REQUIRED_WRITE_QUERY_BUILDER_SQL_PROPERTY,
128124
]
125+
return required_properties
129126
if storage_type == DataNodeConfig._STORAGE_TYPE_VALUE_SQL_TABLE:
130-
if data_node_config.properties:
131-
if engine := data_node_config.properties.get(DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY):
127+
if dn_config_properties:
128+
if engine := dn_config_properties.get(DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY):
132129
if engine == DataNodeConfig._DB_ENGINE_SQLITE:
133130
required_properties = [
134131
DataNodeConfig._REQUIRED_DB_NAME_SQL_PROPERTY,
@@ -143,7 +140,25 @@ def _check_required_properties(self, data_node_config_id: str, data_node_config:
143140
DataNodeConfig._REQUIRED_DB_ENGINE_SQL_PROPERTY,
144141
DataNodeConfig._REQUIRED_TABLE_NAME_SQL_TABLE_PROPERTY,
145142
]
146-
for required_property in required_properties:
143+
return required_properties
144+
return []
145+
146+
def __storage_type_specific_required_properties(self, storage_type: str, dn_config_properties: Dict) -> List:
147+
if storage_type in (DataNodeConfig._STORAGE_TYPE_VALUE_SQL_TABLE, DataNodeConfig._STORAGE_TYPE_VALUE_SQL):
148+
return self.__get_sql_required_properties(storage_type, dn_config_properties)
149+
return []
150+
151+
def _check_required_properties(self, data_node_config_id: str, data_node_config: DataNodeConfig):
152+
storage_type = data_node_config.storage_type
153+
if not storage_type or storage_type not in DataNodeConfig._REQUIRED_PROPERTIES:
154+
return
155+
156+
required_properties = DataNodeConfig._REQUIRED_PROPERTIES[storage_type]
157+
required_properties.extend(
158+
self.__storage_type_specific_required_properties(storage_type, data_node_config.properties)
159+
)
160+
161+
for required_property in set(required_properties):
147162
if not data_node_config.properties or required_property not in data_node_config.properties:
148163
if data_node_config_id == DataNodeConfig._DEFAULT_KEY:
149164
self._warning(

0 commit comments

Comments
 (0)