fix: calculate_age now handles PostgreSQL date objects
All checks were successful
Deploy Development / deploy (push) Successful in 48s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s

Problem: dob Spalte ist DATE (PostgreSQL) → Python bekommt datetime.date,
nicht String → strptime() schlägt fehl → age = "unbekannt"

Fix: Prüfe isinstance(dob, str) und handle beide Typen:
- String → strptime()
- date object → direkt verwenden

Jetzt funktioniert {{age}} Platzhalter korrekt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Lars 2026-03-26 10:19:36 +01:00
parent a9114bc40a
commit 3ad1a19dce

View File

@ -225,16 +225,21 @@ def get_activity_summary(profile_id: str, days: int = 14) -> str:
return f"{row['count']} Einheiten in {days} Tagen (Ø {avg_min} min/Einheit, {int(row['total_kcal'] or 0)} kcal gesamt)" return f"{row['count']} Einheiten in {days} Tagen (Ø {avg_min} min/Einheit, {int(row['total_kcal'] or 0)} kcal gesamt)"
def calculate_age(dob: Optional[str]) -> str: def calculate_age(dob) -> str:
"""Calculate age from date of birth.""" """Calculate age from date of birth (accepts date object or string)."""
if not dob: if not dob:
return "unbekannt" return "unbekannt"
try: try:
birth = datetime.strptime(dob, '%Y-%m-%d') # Handle both datetime.date objects and strings
today = datetime.now() if isinstance(dob, str):
birth = datetime.strptime(dob, '%Y-%m-%d').date()
else:
birth = dob # Already a date object from PostgreSQL
today = datetime.now().date()
age = today.year - birth.year - ((today.month, today.day) < (birth.month, birth.day)) age = today.year - birth.year - ((today.month, today.day) < (birth.month, birth.day))
return str(age) return str(age)
except: except Exception as e:
return "unbekannt" return "unbekannt"