From 8be87bfdfbe4471a40be6231a25b8ec6d9c93f4c Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 27 Mar 2026 07:34:29 +0100 Subject: [PATCH] fix: Remove broken table_exists check Removed faulty EXISTS check that was causing "0" error. Added debug logging and better error messages. Co-Authored-By: Claude Opus 4.6 --- backend/routers/goals.py | 25 +++++------------------ frontend/src/pages/AdminGoalTypesPage.jsx | 7 +++++-- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/backend/routers/goals.py b/backend/routers/goals.py index 98b7521..cce643c 100644 --- a/backend/routers/goals.py +++ b/backend/routers/goals.py @@ -504,26 +504,10 @@ def list_goal_type_definitions(session: dict = Depends(require_auth)): with get_db() as conn: cur = get_cursor(conn) - # 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, + calculation_formula, description, is_system, is_active, created_at, updated_at FROM goal_type_definitions WHERE is_active = true @@ -535,9 +519,10 @@ def list_goal_type_definitions(session: dict = Depends(require_auth)): label_de """) - return [r2d(row) for row in cur.fetchall()] - except HTTPException: - raise + results = [r2d(row) for row in cur.fetchall()] + print(f"[DEBUG] Loaded {len(results)} goal types") + return results + except Exception as e: print(f"[ERROR] list_goal_type_definitions failed: {e}") print(traceback.format_exc()) diff --git a/frontend/src/pages/AdminGoalTypesPage.jsx b/frontend/src/pages/AdminGoalTypesPage.jsx index 9ff50c8..33ecff4 100644 --- a/frontend/src/pages/AdminGoalTypesPage.jsx +++ b/frontend/src/pages/AdminGoalTypesPage.jsx @@ -40,11 +40,14 @@ export default function AdminGoalTypesPage() { const loadGoalTypes = async () => { setLoading(true) + setError(null) try { const data = await api.listGoalTypeDefinitions() - setGoalTypes(data) + console.log('[DEBUG] Loaded goal types:', data) + setGoalTypes(data || []) } catch (err) { - setError('Fehler beim Laden der Goal Types') + console.error('[ERROR] Failed to load goal types:', err) + setError(`Fehler beim Laden der Goal Types: ${err.message || err.toString()}`) } finally { setLoading(false) }