fix: Better error handling for goal types loading
- Check if goal_type_definitions table exists - Detailed error messages - Fallback if goalTypes is empty - Prevent form opening without types Helps debugging Migration 024 issues. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
043bed4323
commit
bbee44ecdc
2 files changed
+63
-29
No files matched your search
+45
-17
@@ -14,6 +14,7 @@ from pydantic import BaseModel
|
||||
from typing import Optional, List
|
||||
from datetime import date, datetime, timedelta
|
||||
from decimal import Decimal
|
||||
import traceback
|
||||
|
||||
from db import get_db, get_cursor, r2d
|
||||
from auth import require_auth
|
||||
@@ -499,24 +500,51 @@ def list_goal_type_definitions(session: dict = Depends(require_auth)):
|
||||
|
||||
Public endpoint - returns all available goal types for dropdown.
|
||||
"""
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("""
|
||||
SELECT id, type_key, label_de, label_en, unit, icon, category,
|
||||
source_table, source_column, aggregation_method,
|
||||
calculation_formula, description, is_system,
|
||||
created_at, updated_at
|
||||
FROM goal_type_definitions
|
||||
WHERE is_active = true
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN is_system = true THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
label_de
|
||||
""")
|
||||
try:
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
|
||||
return [r2d(row) for row in cur.fetchall()]
|
||||
# Check if table exists first
|
||||
cur.execute("""
|
||||
SELECT EXISTS (
|
||||
SELECT FROM information_schema.tables
|
||||
WHERE table_name = 'goal_type_definitions'
|
||||
)
|
||||
""")
|
||||
table_exists = cur.fetchone()[0]
|
||||
|
||||
if not table_exists:
|
||||
print("[ERROR] goal_type_definitions table does not exist!")
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail="Goal Types Tabelle existiert nicht. Migration 024 muss ausgeführt werden."
|
||||
)
|
||||
|
||||
cur.execute("""
|
||||
SELECT id, type_key, label_de, label_en, unit, icon, category,
|
||||
source_table, source_column, aggregation_method,
|
||||
calculation_formula, description, is_system,
|
||||
created_at, updated_at
|
||||
FROM goal_type_definitions
|
||||
WHERE is_active = true
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN is_system = true THEN 0
|
||||
ELSE 1
|
||||
END,
|
||||
label_de
|
||||
""")
|
||||
|
||||
return [r2d(row) for row in cur.fetchall()]
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
print(f"[ERROR] list_goal_type_definitions failed: {e}")
|
||||
print(traceback.format_exc())
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"Fehler beim Laden der Goal Types: {str(e)}"
|
||||
)
|
||||
|
||||
@router.post("/goal-types")
|
||||
def create_goal_type_definition(
|
||||
|
||||
Reference in new issue
Block a user