fix: import NetBox's own users.models.Group, not django.contrib.auth's - #2
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
auth.Groupentirely with its ownusers.models.Group(separate model/table;User.groupspoints there).pipeline.pywas importingdjango.contrib.auth.models.Groupinstead, souser.groups.set([...])got instances NetBox's ownUser.groupsfield couldn't resolve a pk from.TypeError: Field 'id' expected a number but got <Group: storage-admins>— exactly this bug.is_staffassignment — NetBox'sUsermodel has no such field, so it was a silent no-op.testapp/users/— a minimal stand-in mirroring NetBox's actualGroup/Usershape (notdjango.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% coverageuv run pre-commit run --all-files— all hooks passuvx zensical build --clean— docs build cleanimages/netbox-unifi, redeploy to the live cluster, confirm a real SSO login landsnetbox-admins/is_superuser=True