Update main.py
Browse files
main.py
CHANGED
|
@@ -125,6 +125,16 @@ logger = logging.getLogger(__name__)
|
|
| 125 |
# 4. SOZO BUSINESS STUDIO API ENDPOINTS WITH LOGGING
|
| 126 |
# -----------------------------------------------------------------------------
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
@app.route('/api/sozo/projects', methods=['POST'])
|
| 129 |
def create_sozo_project():
|
| 130 |
logger.info("POST /api/sozo/projects - Creating new project")
|
|
@@ -245,21 +255,46 @@ def generate_sozo_report(project_id):
|
|
| 245 |
|
| 246 |
# Ensure chartUrls is a proper list/dict
|
| 247 |
chart_urls = draft_data.get('chartUrls', [])
|
| 248 |
-
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
else:
|
| 251 |
logger.warning(f"Chart URLs is not a list/dict: {type(chart_urls)}")
|
| 252 |
chart_urls = []
|
| 253 |
|
| 254 |
-
|
|
|
|
|
|
|
| 255 |
'status': 'draft',
|
| 256 |
'rawMarkdown': raw_markdown,
|
| 257 |
'chartUrls': chart_urls
|
| 258 |
}
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
logger.info(f"Updating project {project_id} with cleaned data")
|
| 261 |
-
project_ref.update(
|
| 262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
except Exception as update_error:
|
| 264 |
logger.error(f"Error preparing update data for project {project_id}: {str(update_error)}")
|
| 265 |
logger.error(f"Draft data keys: {list(draft_data.keys()) if draft_data else 'None'}")
|
|
|
|
| 125 |
# 4. SOZO BUSINESS STUDIO API ENDPOINTS WITH LOGGING
|
| 126 |
# -----------------------------------------------------------------------------
|
| 127 |
|
| 128 |
+
import logging
|
| 129 |
+
|
| 130 |
+
# Configure console logging
|
| 131 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 132 |
+
logger = logging.getLogger(__name__)
|
| 133 |
+
|
| 134 |
+
# -----------------------------------------------------------------------------
|
| 135 |
+
# 4. SOZO BUSINESS STUDIO API ENDPOINTS WITH LOGGING
|
| 136 |
+
# -----------------------------------------------------------------------------
|
| 137 |
+
|
| 138 |
@app.route('/api/sozo/projects', methods=['POST'])
|
| 139 |
def create_sozo_project():
|
| 140 |
logger.info("POST /api/sozo/projects - Creating new project")
|
|
|
|
| 255 |
|
| 256 |
# Ensure chartUrls is a proper list/dict
|
| 257 |
chart_urls = draft_data.get('chartUrls', [])
|
| 258 |
+
logger.info(f"Chart URLs type: {type(chart_urls)}, count: {len(chart_urls)}")
|
| 259 |
+
logger.info(f"Chart URLs content: {chart_urls}")
|
| 260 |
+
|
| 261 |
+
# Convert chart_urls to a simple serializable format
|
| 262 |
+
if isinstance(chart_urls, dict):
|
| 263 |
+
# Convert dict to list of values or keep as dict but ensure all values are serializable
|
| 264 |
+
serializable_chart_urls = {}
|
| 265 |
+
for key, value in chart_urls.items():
|
| 266 |
+
# Ensure key is string and value is serializable
|
| 267 |
+
clean_key = str(key).replace('\x00', '').replace('\ufeff', '')
|
| 268 |
+
clean_value = str(value).replace('\x00', '').replace('\ufeff', '') if value else ''
|
| 269 |
+
serializable_chart_urls[clean_key] = clean_value
|
| 270 |
+
chart_urls = serializable_chart_urls
|
| 271 |
+
elif isinstance(chart_urls, list):
|
| 272 |
+
# Clean list items
|
| 273 |
+
chart_urls = [str(item).replace('\x00', '').replace('\ufeff', '') for item in chart_urls if item]
|
| 274 |
else:
|
| 275 |
logger.warning(f"Chart URLs is not a list/dict: {type(chart_urls)}")
|
| 276 |
chart_urls = []
|
| 277 |
|
| 278 |
+
# Try to serialize the data to JSON first to catch any issues
|
| 279 |
+
import json
|
| 280 |
+
test_data = {
|
| 281 |
'status': 'draft',
|
| 282 |
'rawMarkdown': raw_markdown,
|
| 283 |
'chartUrls': chart_urls
|
| 284 |
}
|
| 285 |
|
| 286 |
+
# Test JSON serialization
|
| 287 |
+
json_str = json.dumps(test_data, ensure_ascii=False)
|
| 288 |
+
logger.info(f"JSON serialization test passed, length: {len(json_str)}")
|
| 289 |
+
|
| 290 |
logger.info(f"Updating project {project_id} with cleaned data")
|
| 291 |
+
project_ref.update(test_data)
|
| 292 |
|
| 293 |
+
except json.JSONEncodeError as json_error:
|
| 294 |
+
logger.error(f"JSON serialization error for project {project_id}: {str(json_error)}")
|
| 295 |
+
logger.error(f"Problematic data - Raw markdown preview: {raw_markdown[:100]}...")
|
| 296 |
+
logger.error(f"Problematic data - Chart URLs: {chart_urls}")
|
| 297 |
+
raise json_error
|
| 298 |
except Exception as update_error:
|
| 299 |
logger.error(f"Error preparing update data for project {project_id}: {str(update_error)}")
|
| 300 |
logger.error(f"Draft data keys: {list(draft_data.keys()) if draft_data else 'None'}")
|