From a05a407a6bd8cbd745ee2216fbffe4c24bc08f68 Mon Sep 17 00:00:00 2001 From: Gerrod Ubben Date: Wed, 1 Apr 2026 16:30:24 -0400 Subject: [PATCH] Fix --random on reset-admin-password fixes: #7533 --- CHANGES/7533.bugfix | 1 + pulpcore/app/management/commands/reset-admin-password.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 CHANGES/7533.bugfix diff --git a/CHANGES/7533.bugfix b/CHANGES/7533.bugfix new file mode 100644 index 00000000000..35e2cbb24f9 --- /dev/null +++ b/CHANGES/7533.bugfix @@ -0,0 +1 @@ +Fixed `reset-admin-password` command failing when using `--random` option on Django 5. diff --git a/pulpcore/app/management/commands/reset-admin-password.py b/pulpcore/app/management/commands/reset-admin-password.py index f1173940e69..0094392ed87 100644 --- a/pulpcore/app/management/commands/reset-admin-password.py +++ b/pulpcore/app/management/commands/reset-admin-password.py @@ -1,3 +1,6 @@ +import string +import secrets + from getpass import getpass from gettext import gettext as _ @@ -34,7 +37,8 @@ def add_arguments(self, parser): def handle(self, *args, **options): user = User.objects.get_or_create(username="admin", is_superuser=True, is_staff=True)[0] if options["random"]: - password = User.objects.make_random_password(length=20) + alphabet = string.ascii_letters + string.digits + password = "".join(secrets.choice(alphabet) for i in range(20)) user.set_password(password) user.save() self.stdout.write(_('Successfully set "admin" user\'s password to "%s".') % password)