[PR #9554] [MERGED] Fix Django superuser creation failing with ImproperlyConfigured error #8107

Closed
opened 2026-02-26 16:31:49 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/community-scripts/ProxmoxVE/pull/9554
Author: @Copilot
Created: 12/1/2025
Status: Merged
Merged: 12/1/2025
Merged by: @MickLesk

Base: mainHead: copilot/fix-superuser-creation-issue


📝 Commits (3)

  • 17d5af6 Initial plan
  • 2a64a12 Fix Django superuser creation by using manage.py shell
  • 99ddcec Add $STD prefix to superuser creation for consistency

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 install/healthchecks-install.sh (+1 -1)

📄 Description

✍️ 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.

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/community-scripts/ProxmoxVE/pull/9554 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 12/1/2025 **Status:** ✅ Merged **Merged:** 12/1/2025 **Merged by:** [@MickLesk](https://github.com/MickLesk) **Base:** `main` ← **Head:** `copilot/fix-superuser-creation-issue` --- ### 📝 Commits (3) - [`17d5af6`](https://github.com/community-scripts/ProxmoxVE/commit/17d5af6af0ec1277e401347aa19dbf32ed901b33) Initial plan - [`2a64a12`](https://github.com/community-scripts/ProxmoxVE/commit/2a64a127bcb9f60bf5ce0675ebb34913848fc33f) Fix Django superuser creation by using manage.py shell - [`99ddcec`](https://github.com/community-scripts/ProxmoxVE/commit/99ddcecf89c863d980b9abddfb74a900ad34a3ff) Add $STD prefix to superuser creation for consistency ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `install/healthchecks-install.sh` (+1 -1) </details> ### 📄 Description ## ✍️ 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. ```diff -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) - [X] **Self-review completed** – Code follows project standards. - [X] **Tested thoroughly** – Changes work as expected. - [X] **No security risks** – No hardcoded secrets, unnecessary privilege escalations, or permission issues. --- ## 🛠️ Type of Change (**X** in brackets) - [X] 🐞 **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. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> ---- *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? - [x] 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 ```sh 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 ... </details> - Fixes community-scripts/ProxmoxVE#9553 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 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](https://gh.io/copilot-coding-agent-tips) in the docs. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 16:31:49 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ProxmoxVE#8107
No description provided.