Skip to content

Commit 93b9144

Browse files
author
Kazmer, Nagy-Betegh
committed
discovery service config update
1 parent 62bfc7c commit 93b9144

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

lib/idp_common_pkg/idp_common/discovery/classes_discovery.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ def discovery_classes_with_document(self, input_bucket: str, input_prefix: str):
9494
# No need to transform - it's already in the right format
9595
current_class = model_response
9696

97-
custom_item = self.config_manager.get_configuration("Custom")
97+
custom_item_raw = self.config_manager.get_configuration("Custom")
98+
custom_item = cast(Optional[IDPConfig], custom_item_raw)
9899
classes = []
99-
if custom_item and hasattr(custom_item, "classes") and custom_item.classes:
100+
if custom_item and custom_item.classes:
100101
classes = list(custom_item.classes)
101102
# Check for existing class by $id or x-aws-idp-document-type
102103
class_id = current_class.get("$id") or current_class.get(
@@ -115,8 +116,15 @@ def discovery_classes_with_document(self, input_bucket: str, input_prefix: str):
115116
classes.append(current_class)
116117

117118
# Update configuration with new classes
118-
config_data = {"classes": classes}
119-
self.config_manager.save_configuration("Custom", config_data)
119+
# Load existing custom config to preserve all other fields
120+
if not custom_item:
121+
# If no custom config exists, get default as base
122+
default_raw = self.config_manager.get_configuration("Default")
123+
custom_item = cast(Optional[IDPConfig], default_raw) or IDPConfig()
124+
125+
# Update only the classes field, preserving all other config
126+
custom_item.classes = classes
127+
self.config_manager.save_configuration("Custom", custom_item)
120128

121129
return {"status": "SUCCESS"}
122130

@@ -167,9 +175,10 @@ def discovery_classes_with_document_and_ground_truth(
167175
# No need to transform - it's already in the right format
168176
current_class = model_response
169177

170-
custom_item = self.config_manager.get_configuration("Custom")
178+
custom_item_raw = self.config_manager.get_configuration("Custom")
179+
custom_item = cast(Optional[IDPConfig], custom_item_raw)
171180
classes = []
172-
if custom_item and hasattr(custom_item, "classes") and custom_item.classes:
181+
if custom_item and custom_item.classes:
173182
classes = list(custom_item.classes)
174183
# Check for existing class by $id or x-aws-idp-document-type
175184
class_id = current_class.get("$id") or current_class.get(
@@ -188,8 +197,15 @@ def discovery_classes_with_document_and_ground_truth(
188197
classes.append(current_class)
189198

190199
# Update configuration with new classes
191-
config_data = {"classes": classes}
192-
self.config_manager.save_configuration("Custom", config_data)
200+
# Load existing custom config to preserve all other fields
201+
if not custom_item:
202+
# If no custom config exists, get default as base
203+
default_raw = self.config_manager.get_configuration("Default")
204+
custom_item = cast(Optional[IDPConfig], default_raw) or IDPConfig()
205+
206+
# Update only the classes field, preserving all other config
207+
custom_item.classes = classes
208+
self.config_manager.save_configuration("Custom", custom_item)
193209

194210
return {"status": "SUCCESS"}
195211

0 commit comments

Comments
 (0)