Group.objects.all() returns an empty QuerySet #10360

Closed
opened 2025-12-29 21:30:28 +01:00 by adam · 3 comments
Owner

Originally created by @jhofmueller on GitHub (Oct 14, 2024).

Deployment Type

Self-hosted

Triage priority

This is preventing me from using NetBox

NetBox Version

v4.1.3

Python Version

3.12

Steps to Reproduce

  1. Have a netbox instance that has at least one group configured
  2. Start 'nbshell'
  3. Import Group from django.contrib.auth.models
  4. Run Group.objects.all()

Expected Behavior

A QuerySet with the groups configured in NetBox.

Observed Behavior

An empty QuerySet is returned.

Originally created by @jhofmueller on GitHub (Oct 14, 2024). ### Deployment Type Self-hosted ### Triage priority This is preventing me from using NetBox ### NetBox Version v4.1.3 ### Python Version 3.12 ### Steps to Reproduce 1. Have a netbox instance that has at least one group configured 2. Start 'nbshell' 3. Import Group from django.contrib.auth.models 4. Run `Group.objects.all()` ### Expected Behavior A QuerySet with the groups configured in NetBox. ### Observed Behavior An empty QuerySet is returned.
adam added the type: bug label 2025-12-29 21:30:28 +01:00
adam closed this issue 2025-12-29 21:30:28 +01:00
Author
Owner

@Omripresent commented on GitHub (Oct 14, 2024):

I believe as part of v4.0 the user group model was changed to 55fad2f533/netbox/users/models/users.py (L26)

Try using from users.models import Group and then Group.objects.all()

@Omripresent commented on GitHub (Oct 14, 2024): I believe as part of v4.0 the user group model was changed to https://github.com/netbox-community/netbox/blob/55fad2f533d9a0190ee9b5cf7c32bf173c982794/netbox/users/models/users.py#L26 Try using `from users.models import Group` and then `Group.objects.all()`
Author
Owner

@jhofmueller commented on GitHub (Oct 15, 2024):

Shame on me! I missed the "NetBox now uses custom User and Group models rather than the stock models provided by Django". Thanks for the hint!

@jhofmueller commented on GitHub (Oct 15, 2024): Shame on me! I missed the "NetBox now uses custom User and Group models rather than the stock models provided by Django". Thanks for the hint!
Author
Owner

@jeremystretch commented on GitHub (Oct 15, 2024):

Just an FYI to help avoid future confusion: The nbshell environment will automatically import users.models.Group:

$ ./manage.py nbshell
### NetBox interactive shell (jstretch-workstation)
### Python 3.10.12 | Django 5.0.9 | NetBox NetBox Community v4.1.3
### lsmodels() will show available models. Use help(<model>) for more info.
>>> Group
<class 'users.models.users.Group'>

However, importing Django's stock Group model will override this in the global namespace, and should be avoided:

>>> from django.contrib.auth.models import Group
>>> Group
<class 'django.contrib.auth.models.Group'>
@jeremystretch commented on GitHub (Oct 15, 2024): Just an FYI to help avoid future confusion: The `nbshell` environment will automatically import `users.models.Group`: ``` $ ./manage.py nbshell ### NetBox interactive shell (jstretch-workstation) ### Python 3.10.12 | Django 5.0.9 | NetBox NetBox Community v4.1.3 ### lsmodels() will show available models. Use help(<model>) for more info. >>> Group <class 'users.models.users.Group'> ``` However, importing Django's stock Group model will override this in the global namespace, and should be avoided: ``` >>> from django.contrib.auth.models import Group >>> Group <class 'django.contrib.auth.models.Group'> ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10360