createsuperuser management command fails #11609

Closed
opened 2025-12-29 21:47:35 +01:00 by adam · 6 comments
Owner

Originally created by @arthanson on GitHub (Sep 12, 2025).

Originally assigned to: @pheus on GitHub.

NetBox Edition

NetBox Community

NetBox Version

v4.5.0 cfcea7c941

Python Version

3.10

Steps to Reproduce

  1. Go to current feature branch of NetBox (commit: cfcea7c941)
  2. Run the management command 'createsuperuser'
  3. Fill out the details of name, email, password

Expected Behavior

The management command should run and create a new user

Observed Behavior

Get a TypeError: User() got unexpected keyword arguments: 'is_staff'

Originally created by @arthanson on GitHub (Sep 12, 2025). Originally assigned to: @pheus on GitHub. ### NetBox Edition NetBox Community ### NetBox Version v4.5.0 cfcea7c9418649491c5540adf650621b04f75091 ### Python Version 3.10 ### Steps to Reproduce 1. Go to current feature branch of NetBox (commit: cfcea7c9418649491c5540adf650621b04f75091) 2. Run the management command 'createsuperuser' 3. Fill out the details of name, email, password ### Expected Behavior The management command should run and create a new user ### Observed Behavior Get a `TypeError: User() got unexpected keyword arguments: 'is_staff'`
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:47:35 +01:00
adam closed this issue 2025-12-29 21:47:35 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 12, 2025):

This was caused by removing the is_staff field from the User model under #16137.

@jeremystretch commented on GitHub (Sep 12, 2025): This was caused by removing the `is_staff` field from the User model under #16137.
Author
Owner

@pheus commented on GitHub (Sep 13, 2025):

It seems the create_superuser() method of Django’s UserManager needs to be overridden, similar to create_user().

Django supports async operations (see the async docs). Although NetBox doesn’t run under ASGI, should we also include async counterparts for parity?

I’d like to contribute this fix. Could you please assign the issue to me? Thanks!

@pheus commented on GitHub (Sep 13, 2025): It seems the `create_superuser()` method of Django’s `UserManager` needs to be **overridden**, similar to `create_user()`. Django supports async operations (see the [async docs](https://docs.djangoproject.com/en/5.2/topics/async/)). Although NetBox doesn’t run under ASGI, should we also include async counterparts for parity? I’d like to contribute this fix. Could you please assign the issue to me? Thanks!
Author
Owner

@jnovinger commented on GitHub (Sep 14, 2025):

All yours, @pheus . Which async operations are you thinking of?

Also, please make sure the PR targets feature for this one.

@jnovinger commented on GitHub (Sep 14, 2025): All yours, @pheus . Which async operations are you thinking of? Also, please make sure the PR targets `feature` for this one.
Author
Owner

@pheus commented on GitHub (Sep 14, 2025):

Thanks, @jnovinger! I’ll open the PR against feature.

Re async: I’m referring to Django’s UserManager.acreate_user() and acreate_superuser(). Both default to setting is_staff, so they’d hit the same issue if/when NetBox runs under ASGI. I can mirror the sync override for those (drop is_staff; enforce is_superuser=True).
Would you like me to include the async variants in this PR, or keep it sync‑only?

    def create_user(self, username, email=None, password=None, **extra_fields):
        extra_fields.setdefault("is_staff", False)
        extra_fields.setdefault("is_superuser", False)
        return self._create_user(username, email, password, **extra_fields)

    async def acreate_user(self, username, email=None, password=None, **extra_fields):
        extra_fields.setdefault("is_staff", False)
        extra_fields.setdefault("is_superuser", False)
        return await self._acreate_user(username, email, password, **extra_fields)

Ref: 1dbf415a18/django/contrib/auth/models.py (L172-L212)

@pheus commented on GitHub (Sep 14, 2025): Thanks, @jnovinger! I’ll open the PR against `feature`. Re async: I’m referring to Django’s `UserManager.acreate_user()` and `acreate_superuser()`. Both default to setting `is_staff`, so they’d hit the same issue if/when NetBox runs under ASGI. I can mirror the sync override for those (drop `is_staff`; enforce `is_superuser=True`). Would you like me to include the async variants in this PR, or keep it sync‑only? ```python def create_user(self, username, email=None, password=None, **extra_fields): extra_fields.setdefault("is_staff", False) extra_fields.setdefault("is_superuser", False) return self._create_user(username, email, password, **extra_fields) async def acreate_user(self, username, email=None, password=None, **extra_fields): extra_fields.setdefault("is_staff", False) extra_fields.setdefault("is_superuser", False) return await self._acreate_user(username, email, password, **extra_fields) ``` Ref: https://github.com/django/django/blob/1dbf415a1829a0bacd8cb31a8da5f2a99c5ea465/django/contrib/auth/models.py#L172-L212
Author
Owner

@jnovinger commented on GitHub (Sep 15, 2025):

Ah, thanks. I somehow completely missed those when I looked. 🤦

I'd lean toward also covering them, for safety sake, even though we're not currently using them. My thinking is we've got the context now, why not use it, rather than wait for a bug report later and have to investigate again.

@jnovinger commented on GitHub (Sep 15, 2025): Ah, thanks. I somehow completely missed those when I looked. 🤦 I'd lean toward also covering them, for safety sake, even though we're not currently using them. My thinking is we've got the context now, why not use it, rather than wait for a bug report later and have to investigate again.
Author
Owner

@pheus commented on GitHub (Sep 15, 2025):

Thanks, @jnovinger ! Totally agree.
I’ve updated the PR to include the async counterparts (acreate_user and acreate_superuser) mirroring the sync changes. Appreciate the guidance!

@pheus commented on GitHub (Sep 15, 2025): Thanks, @jnovinger ! Totally agree. I’ve updated the PR to include the async counterparts (`acreate_user` and `acreate_superuser`) mirroring the sync changes. Appreciate the guidance!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11609