Spaces:
Building
Building
Update config_provider.py
Browse files- config_provider.py +37 -0
config_provider.py
CHANGED
@@ -77,6 +77,12 @@ class ConfigProvider:
|
|
77 |
if 'projects' in config_data and len(config_data['projects']) > 0:
|
78 |
first_project = config_data['projects'][0]
|
79 |
log_debug(f"π Raw project data - last_update_date: {first_project.get('last_update_date')}")
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# Ensure required fields
|
82 |
if 'config' not in config_data:
|
@@ -85,6 +91,18 @@ class ConfigProvider:
|
|
85 |
# Parse API configs (handle JSON strings)
|
86 |
if 'apis' in config_data:
|
87 |
cls._parse_api_configs(config_data['apis'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
# Validate and create model
|
90 |
cfg = ServiceConfig.model_validate(config_data)
|
@@ -93,6 +111,10 @@ class ConfigProvider:
|
|
93 |
if cfg.projects and len(cfg.projects) > 0:
|
94 |
log_debug(f"π Parsed project - last_update_date: {cfg.projects[0].last_update_date}")
|
95 |
log_debug(f"π Type: {type(cfg.projects[0].last_update_date)}")
|
|
|
|
|
|
|
|
|
96 |
|
97 |
log_debug(
|
98 |
"Configuration loaded",
|
@@ -154,6 +176,17 @@ class ConfigProvider:
|
|
154 |
# Load current config for race condition check
|
155 |
try:
|
156 |
current_config = cls._load()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
# Check for race condition
|
159 |
if config.last_update_date and current_config.last_update_date:
|
@@ -615,6 +648,10 @@ class ConfigProvider:
|
|
615 |
# Ensure published is a boolean (safety check)
|
616 |
if version.published is None:
|
617 |
version.published = False
|
|
|
|
|
|
|
|
|
618 |
|
619 |
# Published versions cannot be edited
|
620 |
if version.published:
|
|
|
77 |
if 'projects' in config_data and len(config_data['projects']) > 0:
|
78 |
first_project = config_data['projects'][0]
|
79 |
log_debug(f"π Raw project data - last_update_date: {first_project.get('last_update_date')}")
|
80 |
+
# Check versions published status
|
81 |
+
if 'versions' in first_project:
|
82 |
+
for version in first_project['versions']:
|
83 |
+
if 'published' in version:
|
84 |
+
log_debug(f"π Version {version.get('no')} - raw published: {version['published']} (type: {type(version['published'])})")
|
85 |
+
|
86 |
|
87 |
# Ensure required fields
|
88 |
if 'config' not in config_data:
|
|
|
91 |
# Parse API configs (handle JSON strings)
|
92 |
if 'apis' in config_data:
|
93 |
cls._parse_api_configs(config_data['apis'])
|
94 |
+
|
95 |
+
# Fix boolean values in versions before validation
|
96 |
+
if 'projects' in config_data:
|
97 |
+
for project in config_data['projects']:
|
98 |
+
if 'versions' in project:
|
99 |
+
for version in project['versions']:
|
100 |
+
# Ensure published is boolean
|
101 |
+
if 'published' in version:
|
102 |
+
if isinstance(version['published'], str):
|
103 |
+
version['published'] = version['published'].lower() == 'true'
|
104 |
+
elif version['published'] is None:
|
105 |
+
version['published'] = False
|
106 |
|
107 |
# Validate and create model
|
108 |
cfg = ServiceConfig.model_validate(config_data)
|
|
|
111 |
if cfg.projects and len(cfg.projects) > 0:
|
112 |
log_debug(f"π Parsed project - last_update_date: {cfg.projects[0].last_update_date}")
|
113 |
log_debug(f"π Type: {type(cfg.projects[0].last_update_date)}")
|
114 |
+
|
115 |
+
# Log versions published status after parsing
|
116 |
+
for version in cfg.projects[0].versions:
|
117 |
+
log_debug(f"π Parsed version {version.no} - published: {version.published} (type: {type(version.published)})")
|
118 |
|
119 |
log_debug(
|
120 |
"Configuration loaded",
|
|
|
176 |
# Load current config for race condition check
|
177 |
try:
|
178 |
current_config = cls._load()
|
179 |
+
|
180 |
+
# Ensure boolean values remain boolean in versions
|
181 |
+
if 'projects' in config_dict:
|
182 |
+
for project in config_dict['projects']:
|
183 |
+
if 'versions' in project:
|
184 |
+
for version in project['versions']:
|
185 |
+
# Force published to be boolean
|
186 |
+
if 'published' in version:
|
187 |
+
version['published'] = bool(version['published'])
|
188 |
+
if 'deleted' in version:
|
189 |
+
version['deleted'] = bool(version['deleted'])
|
190 |
|
191 |
# Check for race condition
|
192 |
if config.last_update_date and current_config.last_update_date:
|
|
|
648 |
# Ensure published is a boolean (safety check)
|
649 |
if version.published is None:
|
650 |
version.published = False
|
651 |
+
|
652 |
+
# Convert to boolean if it's a string
|
653 |
+
if isinstance(version.published, str):
|
654 |
+
version.published = version.published.lower() == 'true'
|
655 |
|
656 |
# Published versions cannot be edited
|
657 |
if version.published:
|