Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

✍️ Description

Django superuser creation in healthchecks installation fails with django.core.exceptions.ImproperlyConfigured: Requested setting AUTH_USER_MODEL, but settings are not configured.

Root cause: Python executed directly without Django settings initialization.

Fix: Use manage.py shell to properly load Django settings before executing superuser creation code.

-python <<EOF
+$STD python manage.py shell <<EOF
 from django.contrib.auth import get_user_model
 User = get_user_model()
 if not User.objects.filter(email="${ADMIN_EMAIL}").exists():
     User.objects.create_superuser("${ADMIN_EMAIL}", "${ADMIN_EMAIL}", "${ADMIN_PASSWORD}")
 EOF

This aligns with the pattern used in netbox-install.sh and other Django-based scripts in the repository.

🔗 Related PR / Issue

Link: #4927

✅ Prerequisites (X in brackets)

  • Self-review completed – Code follows project standards.
  • Tested thoroughly – Changes work as expected.
  • No security risks – No hardcoded secrets, unnecessary privilege escalations, or permission issues.

🛠️ Type of Change (X in brackets)

  • 🐞 Bug fix – Resolves an issue without breaking functionality.
  • New feature – Adds new, non-breaking functionality.
  • 💥 Breaking change – Alters existing functionality in a way that may require updates.
  • 🆕 New script – A fully functional and tested script or script set.
  • 🌍 Website update – Changes to website-related JSON files or metadata.
  • 🔧 Refactoring / Code Cleanup – Improves readability or maintainability without changing functionality.
  • 📝 Documentation update – Changes to README, AppName.md, CONTRIBUTING.md, or other docs.
Original prompt

This section details on the original issue you should resolve

<issue_title>Healthchecks: django.core.exceptions.ImproperlyConfigured on creation of superuser</issue_title>
<issue_description>### ✅ Have you read and understood the above guidelines?

yes

🔎 Did you run the script with verbose mode enabled?

Yes, verbose mode was enabled and the output is included below

📜 What is the name of the script you are using?

Healthchecks

📂 What was the exact command used to execute the script?

bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/healthchecks.sh)"

⚙️ What settings are you using?

  • Default Settings
  • Advanced Settings

🖥️ Which Linux distribution are you using?

Debian 13

📈 Which Proxmox version are you on?

pve-manager/8.4.1/2a5fa54a8503f96d (running kernel: 6.8.12-10-pve)

📝 Provide a clear and concise description of the issue.

Creation of superuser for healthchecks fails on fresh install

django.core.exceptions.ImproperlyConfigured: Requested setting AUTH_USER_MODEL, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

[ERROR] in line 92: exit code 0: while executing command python <<EOF
from django.contrib.auth import get_user_model
User = get_user_model()
if not User.objects.filter(email="${ADMIN_EMAIL}").exists():
    User.objects.create_superuser("${ADMIN_EMAIL}", "${ADMIN_EMAIL}", "${ADMIN_PASSWORD}")
EOF

🔄 Steps to reproduce the issue.

Fresh install using bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/healthchecks.sh)"

❌ Paste the full error output (if available).

fixing permissions on existing directory /var/lib/postgresql/16/main ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Berlin
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Processing triggers for man-db (2.13.1-1) ...
Processing triggers for libc-bin (2.41-12) ...
✔️ Setup PostgreSQL 16
⏳ Setting up PostgreSQL DatabaseCREATE ROLE
CREATE DATABASE
ALTER ROLE
ALTER ROLE
ALTER ROLE
✔️ Set up PostgreSQL Database
✔️ Set up Keys
✔️ Deployed: healthchecks (3.13)
⏳ Installing Healthchecks (venv)Requirement already satisfied: pip in ./venv/lib/python3.13/site-packages (25.1.1)
Collecting pip
Downloading pip-25.3-py3-none-any.whl.metadata (4.7 kB)
Collecting wheel
Downloading wheel-0.45.1-py3-none-any.whl.metadata (2.3 kB)
Downloading pip-25.3-py3-none-any.whl (1.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 6.4 MB/s eta 0:00:00
Downloading wheel-0.45.1-py3-none-any.whl (72 kB)
Installing collected packages: wheel, pip
Attempting uninstall: pip
Found existing installation: pip 25.1.1
Uninstalling pip-25.1.1:
Successfully uninstalled pip-25.1.1
Successfully installed pip-25.3 wheel-0.45.1
Collecting gunicorn
Downloading gunicorn-23.0.0-py3-none-any.whl.metadata (4.4 kB)
Collecting aiosmtpd==1.4.6 (from -r requirements.txt (line 1))
Downloading aiosmtpd-1.4.6-py3-none-any.whl.metadata (6.6 kB)
Collecting cronsim==2.7 (from -r requirements.txt (line 2))
Downloading cronsim-2.7-py3-none-any.whl.metadata (6.9 kB)
Collecting Django==5.2.8 (from -r requirements.txt (line 3))
Downloading django-5.2.8-py3-none-any.whl.metadata (4.1 kB)
Collecting django-compressor==4.6 (from -r requirements.txt (line 4))
Downloading django_compressor-4.6.0-py3-none-any.whl.metadata (5.2 kB)
Collecting django-stubs-ext==5.2.7 (from -r requirements.txt (line 5))
Downloading django_stubs_ext-5.2.7-py3-none-any.whl.metadata (3.6 kB)
Collecting fido2==2.0.0 (from -r requirements.txt (line 6))
Downloading fido2-2.0.0-py3-none-any.whl.metadata (7.1 kB)
Collecting oncalendar==1.1 (from -r requirements.txt (line 7))
Downloading oncalendar-1.1.tar.gz (8.7 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting psycopg==3.2.13 (from -r requirements.txt (line 8))
Downloading psycopg-3.2.13-py3-none-any.whl.metadata (4.5 kB)
Collecting pycurl==7.45.7 (from -r requirements.txt (line 9))
Downloading pycurl-7.45.7-cp313-cp313-manylinux_2_28_x86_64.whl.metadata (4.5 kB)
Collecting pydantic==2.12.5 (from -r requirements.txt (line 10))
Downloading pydantic-2.12.5-py3-none-any.whl.metadata (90 kB)
Collecting PyJWT==2.10.1 (from PyJWT[crypto]==2.10.1->-r requirements.txt (line 11))
Downloading PyJWT-2.10.1-py3-none-any.whl.metadata (4.0 kB)
Collecting pyotp==2.9.0 (from -r requirements.txt (line 12))
Downloading pyotp-2.9.0-py3-none-any.whl.metadata (9.8 kB)
Collecting segno==1.6.6 (from ...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix django core improperly configured error on superuser creation Fix Django superuser creation failing with ImproperlyConfigured error Dec 1, 2025
Copilot AI requested a review from MickLesk December 1, 2025 18:59
@MickLesk MickLesk marked this pull request as ready for review December 1, 2025 19:07
@MickLesk MickLesk requested a review from a team as a code owner December 1, 2025 19:07
@github-actions github-actions bot added bugfix update script A change that updates a script labels Dec 1, 2025
@MickLesk MickLesk merged commit c5eae09 into main Dec 1, 2025
6 checks passed
probers1 pushed a commit to probers1/ProxmoxVE that referenced this pull request Dec 5, 2025
…community-scripts#9554)

* Initial plan

* Fix Django superuser creation by using manage.py shell

Co-authored-by: MickLesk <[email protected]>

* Add $STD prefix to superuser creation for consistency

Co-authored-by: MickLesk <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: MickLesk <[email protected]>
@MickLesk MickLesk deleted the copilot/fix-superuser-creation-issue branch December 8, 2025 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix update script A change that updates a script

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Healthchecks: django.core.exceptions.ImproperlyConfigured on creation of superuser

2 participants