#!/usr/bin/env python # -*- coding: utf-8 -*- """ Check database for SystemConfig issues """ import os import sys import django # Setup Django environment sys.path.insert(0, os.path.dirname(__file__)) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings') django.setup() from dvadmin.system.models import SystemConfig print("=" * 60) print("Checking SystemConfig Database") print("=" * 60) try: # Check if table exists and has data count = SystemConfig.objects.count() print(f"\n✓ SystemConfig table exists") print(f"✓ Found {count} records") if count == 0: print("\n⚠ WARNING: No system config records found!") print(" You may need to run: python manage.py init") else: # Check for problematic records print("\nChecking for problematic records...") configs = SystemConfig.objects.filter(parent_id__isnull=False).values( 'id', 'parent__key', 'key', 'value', 'form_item_type' )[:10] print(f"\nFirst 10 config records:") for config in configs: key_name = f"{config.get('parent__key')}.{config.get('key')}" value = config.get('value') print(f" - {key_name}: {type(value).__name__} = {str(value)[:50]}...") # Try to build the config dict like dispatch does print("\n" + "=" * 60) print("Testing config building (like dispatch.py does)...") print("=" * 60) from application.dispatch import _get_all_system_config try: data = _get_all_system_config() print(f"\n✓ Successfully built config dict with {len(data)} keys") print("\nSample keys:") for i, (k, v) in enumerate(list(data.items())[:5]): print(f" - {k}: {type(v).__name__}") if i >= 4: break except Exception as e: print(f"\n✗ ERROR building config: {e}") import traceback traceback.print_exc() except Exception as e: print(f"\n✗ ERROR: {e}") import traceback traceback.print_exc() print("\n" + "=" * 60)