Skip to content

fix: import NetBox's own users.models.Group, not django.contrib.auth's - #2

Merged
dcode merged 1 commit into
mainfrom
fix-users-group-import
Aug 25, 2026
Merged

fix: import NetBox's own users.models.Group, not django.contrib.auth's#2
dcode merged 1 commit into
mainfrom
fix-users-group-import

Conversation

@dcode

@dcode dcode commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • NetBox 4.x replaces Django's stock auth.Group entirely with its own users.models.Group (separate model/table; User.groups points there). pipeline.py was importing django.contrib.auth.models.Group instead, so user.groups.set([...]) got instances NetBox's own User.groups field couldn't resolve a pk from.
  • Confirmed live at local instance: SSO login failed with TypeError: Field 'id' expected a number but got <Group: storage-admins> — exactly this bug.
  • Also drops the is_staff assignment — NetBox's User model has no such field, so it was a silent no-op.
  • Added testapp/users/ — a minimal stand-in mirroring NetBox's actual Group/User shape (not django.contrib.auth's) — so tests now exercise the real import path and would have caught this.

Test plan

  • uv run pytest --cov=src --cov-fail-under=100 — 12/12 passing, 100% coverage
  • uv run pre-commit run --all-files — all hooks pass
  • uvx zensical build --clean — docs build clean
  • Rebuild images/netbox-unifi, redeploy to the live cluster, confirm a real SSO login lands netbox-admins/is_superuser=True

NetBox 4.x replaces Django's stock auth.Group entirely with its own
users.models.Group (separate model/table; User.groups points there).
Importing the wrong one produced instances NetBox's own User.groups
field can't resolve a pk from, surfacing at real login as:
TypeError: Field 'id' expected a number but got <Group: storage-admins>.

Also drops the is_staff assignment -- NetBox's User model has no such
field, so it was a silent no-op. Test suite now runs against a small
testapp/users stand-in that mirrors NetBox's actual Group/User shape
(not django.contrib.auth's), so this exact bug is caught going forward.
@dcode
dcode merged commit e6a8028 into main Aug 25, 2026
3 checks passed
@dcode
dcode deleted the fix-users-group-import branch August 25, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant