test
This commit is contained in:
parent
8f324d99f5
commit
a84edb734a
@ -1,6 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from django.core.management import execute_from_command_line
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -15,6 +16,14 @@ class UsersConfig(AppConfig):
|
|||||||
|
|
||||||
# Only run when the server is actually starting
|
# Only run when the server is actually starting
|
||||||
if 'runserver' in sys.argv:
|
if 'runserver' in sys.argv:
|
||||||
|
# Defer the superuser creation to avoid database access during app initialization
|
||||||
|
# This prevents the Django warning about accessing database during app initialization
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
|
def create_superuser_if_needed():
|
||||||
|
# Wait a bit to ensure Django is fully ready
|
||||||
|
time.sleep(0.1)
|
||||||
try:
|
try:
|
||||||
from .models import User
|
from .models import User
|
||||||
from decouple import config
|
from decouple import config
|
||||||
@ -64,3 +73,8 @@ class UsersConfig(AppConfig):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Don't fail the entire Django startup if there's an error
|
# Don't fail the entire Django startup if there's an error
|
||||||
logger.error(f'Error creating admin user: {e}')
|
logger.error(f'Error creating admin user: {e}')
|
||||||
|
|
||||||
|
# Start the superuser creation in a separate thread to avoid the warning
|
||||||
|
thread = threading.Thread(target=create_superuser_if_needed, daemon=True)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user