Add detailed logging to debug template creation
Browse files
main.py
CHANGED
|
@@ -744,11 +744,12 @@ async def ensure_default_template_exists():
|
|
| 744 |
Creates it if it doesn't exist.
|
| 745 |
"""
|
| 746 |
try:
|
|
|
|
| 747 |
# Check if template exists
|
| 748 |
template = await db.checklist_templates.find_one({"templateId": "default"})
|
| 749 |
|
| 750 |
if not template:
|
| 751 |
-
logger.info("Default template not found, creating it...")
|
| 752 |
|
| 753 |
# Create the default template
|
| 754 |
default_template = {
|
|
@@ -850,14 +851,16 @@ async def ensure_default_template_exists():
|
|
| 850 |
}
|
| 851 |
|
| 852 |
result = await db.checklist_templates.insert_one(default_template)
|
| 853 |
-
logger.info(f"
|
| 854 |
-
return
|
|
|
|
|
|
|
| 855 |
else:
|
| 856 |
-
logger.info("Default template already exists")
|
| 857 |
return template
|
| 858 |
|
| 859 |
except Exception as e:
|
| 860 |
-
logger.error(f"Error ensuring default template exists: {e}")
|
| 861 |
return None
|
| 862 |
|
| 863 |
@app.get("/api/checklist-template/default", response_model=Dict[str, Any])
|
|
@@ -872,13 +875,15 @@ async def get_default_checklist_template():
|
|
| 872 |
HTTPException: If template not found or database operation fails
|
| 873 |
"""
|
| 874 |
try:
|
| 875 |
-
logger.info("Retrieving default checklist template")
|
| 876 |
|
| 877 |
# Ensure template exists (creates if not found)
|
| 878 |
template_doc = await ensure_default_template_exists()
|
|
|
|
| 879 |
|
| 880 |
if not template_doc:
|
| 881 |
# Fallback to looking for old template ID
|
|
|
|
| 882 |
template_doc = await db.checklist_templates.find_one({"templateId": "default-audit-checklist"})
|
| 883 |
|
| 884 |
if not template_doc:
|
|
|
|
| 744 |
Creates it if it doesn't exist.
|
| 745 |
"""
|
| 746 |
try:
|
| 747 |
+
logger.info("Checking if default template exists...")
|
| 748 |
# Check if template exists
|
| 749 |
template = await db.checklist_templates.find_one({"templateId": "default"})
|
| 750 |
|
| 751 |
if not template:
|
| 752 |
+
logger.info("Default template not found, creating it now...")
|
| 753 |
|
| 754 |
# Create the default template
|
| 755 |
default_template = {
|
|
|
|
| 851 |
}
|
| 852 |
|
| 853 |
result = await db.checklist_templates.insert_one(default_template)
|
| 854 |
+
logger.info(f"✅ Successfully created default template with ID: {result.inserted_id}")
|
| 855 |
+
# Fetch the newly created template to return with _id
|
| 856 |
+
template = await db.checklist_templates.find_one({"templateId": "default"})
|
| 857 |
+
return template
|
| 858 |
else:
|
| 859 |
+
logger.info("✅ Default template already exists in database")
|
| 860 |
return template
|
| 861 |
|
| 862 |
except Exception as e:
|
| 863 |
+
logger.error(f"❌ Error ensuring default template exists: {e}", exc_info=True)
|
| 864 |
return None
|
| 865 |
|
| 866 |
@app.get("/api/checklist-template/default", response_model=Dict[str, Any])
|
|
|
|
| 875 |
HTTPException: If template not found or database operation fails
|
| 876 |
"""
|
| 877 |
try:
|
| 878 |
+
logger.info("📋 GET /api/checklist-template/default - Retrieving default checklist template")
|
| 879 |
|
| 880 |
# Ensure template exists (creates if not found)
|
| 881 |
template_doc = await ensure_default_template_exists()
|
| 882 |
+
logger.info(f"Template check result: {'Found' if template_doc else 'Not Found'}")
|
| 883 |
|
| 884 |
if not template_doc:
|
| 885 |
# Fallback to looking for old template ID
|
| 886 |
+
logger.info("Checking for old template ID: default-audit-checklist")
|
| 887 |
template_doc = await db.checklist_templates.find_one({"templateId": "default-audit-checklist"})
|
| 888 |
|
| 889 |
if not template_doc:
|