#!/usr/bin/env python3 """ Debug script to check user and their relationships """ import os import sys from dotenv import load_dotenv # Load environment variables load_dotenv() # Add current directory to Python path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from flask import Flask from models import db, User, Introduction, ProfileSummary, WorkExperience, Project, Education, Skill, Achievement, ProfileSectionOrder def debug_user_relationships(user_email): """Debug user relationships""" app = Flask(__name__) app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'dev-secret-key-change-in-production') app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app) with app.app_context(): user = User.query.filter_by(email=user_email).first() if not user: print(f"User {user_email} not found") return print(f"User: {user.email} (ID: {user.id})") print(f"Is admin: {user.is_admin}") # Check relationships print("\nProfile data:") print(f"Introduction: {user.introduction}") print(f"Profile Summary: {user.profile_summary}") print(f"Work experiences: {len(user.work_experiences)}") print(f"Projects: {len(user.projects)}") print(f"Education: {len(user.educations)}") print(f"Skills: {len(user.skills)}") print(f"Achievements: {len(user.achievements)}") print(f"Section order: {user.section_order}") # Check direct queries print("\nDirect database queries:") intro = Introduction.query.filter_by(user_id=user.id).first() print(f"Direct intro query: {intro}") # Check if user has any introductions from sqlalchemy import text result = db.session.execute(text("SELECT COUNT(*) FROM introductions WHERE user_id = :user_id"), {'user_id': str(user.id)}) count = result.scalar() print(f"Introduction count from direct SQL: {count}") if __name__ == '__main__': debug_user_relationships('test1@example.com')