Django Permission 'codenames` Duplicated #2156

Closed
opened 2025-12-29 17:22:47 +01:00 by adam · 2 comments
Owner

Originally created by @bdlamprecht on GitHub (Nov 28, 2018).

Environment

  • Python version: 3.6
  • NetBox version: v2.5-beta2

Steps to Reproduce

I'm using @cimnine's Docker deployment instructions mentioned here.
Although I couldn't get that one-liner to work for whatever reason, if I manually execute that code, I still see these permission codenames:

add_interface
add_interfaceconnection
change_interface
change_interfaceconnection
delete_interface
delete_interfaceconnection
view_interface
view_interfaceconnection
add_interfaceconnection         <- Duplicated
change_interfaceconnection      <- Duplicated
delete_interfaceconnection      <- Duplicated
view_interfaceconnection        <- Duplicated

This causes problems as it is expected for each permission to have a unique codename.

Expected Behavior

The permissions should take effect without erroring out.

Observed Behavior

When I try and bring up my Dockerized version of NetBox using v2.5-beta2, I get this error:

  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 403, in get
    (self.model._meta.object_name, num)
django.contrib.auth.models.MultipleObjectsReturned: get() returned more than one Permission -- it returned 2!
Originally created by @bdlamprecht on GitHub (Nov 28, 2018). ### Environment * Python version: 3.6 * NetBox version: v2.5-beta2 ### Steps to Reproduce I'm using @cimnine's Docker deployment instructions mentioned [here](https://github.com/ninech/netbox-docker#available-groups-for-usergroup-initializers). Although I couldn't get that one-liner to work for whatever reason, if I manually execute that code, I still see these permission `codenames`: ``` add_interface add_interfaceconnection change_interface change_interfaceconnection delete_interface delete_interfaceconnection view_interface view_interfaceconnection add_interfaceconnection <- Duplicated change_interfaceconnection <- Duplicated delete_interfaceconnection <- Duplicated view_interfaceconnection <- Duplicated ``` This causes problems as it is expected for each permission to have a unique `codename`. <!-- What did you expect to happen? --> ### Expected Behavior The permissions should take effect without erroring out. <!-- What happened instead? --> ### Observed Behavior When I try and bring up my Dockerized version of NetBox using `v2.5-beta2`, I get this error: ``` File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 403, in get (self.model._meta.object_name, num) django.contrib.auth.models.MultipleObjectsReturned: get() returned more than one Permission -- it returned 2! ```
adam added the type: bugstatus: accepted labels 2025-12-29 17:22:47 +01:00
adam closed this issue 2025-12-29 17:22:47 +01:00
Author
Owner

@bdlamprecht commented on GitHub (Nov 28, 2018):

This is a screenshot from the WebUI admin page:
image

You can see the duplicated permissions much easier this way.

@bdlamprecht commented on GitHub (Nov 28, 2018): This is a screenshot from the WebUI admin page: ![image](https://user-images.githubusercontent.com/7783306/49171054-dee38a80-f2fa-11e8-90c8-5ca6cf492adf.png) You can see the duplicated permissions much easier this way.
Author
Owner

@jeremystretch commented on GitHub (Nov 28, 2018):

This is happening because we delete the InterfaceConnection model and then introduce a new InterfaceConnection proxy model in the 0066_cables DCIM migration under v2.5. For reference:

v2.4.8:

netbox=> select * from auth_permission where codename like '%interfaceconnection%';
 id  |              name               | content_type_id |          codename          
-----+---------------------------------+-----------------+----------------------------
 112 | Can add interface connection    |              38 | add_interfaceconnection
 113 | Can change interface connection |              38 | change_interfaceconnection
 114 | Can delete interface connection |              38 | delete_interfaceconnection
(3 rows)

After migrating to v2.5-beta2:

netbox=> select * from auth_permission where codename like '%interfaceconnection%';
 id  |              name               | content_type_id |          codename          
-----+---------------------------------+-----------------+----------------------------
 112 | Can add interface connection    |              38 | add_interfaceconnection
 113 | Can change interface connection |              38 | change_interfaceconnection
 114 | Can delete interface connection |              38 | delete_interfaceconnection
 315 | Can add interface connection    |              37 | add_interfaceconnection
 316 | Can change interface connection |              37 | change_interfaceconnection
 317 | Can delete interface connection |              37 | delete_interfaceconnection
 318 | Can view interface connection   |              37 | view_interfaceconnection
(7 rows)

So there are actually two issues here:

  1. The content type and permissions for the old InterfaceConnection model aren't getting deleted along with the model. This appears to be normal Django behavior, but we can accomplish this manually in the migration.

  2. The new proxy console/power/interface connection models are getting add/change/delete permissions created for them, which are unnecessary and unusable. I'll open a new issue for this second point.

In the meantime, this can be resolved by cleaning out stale content types with the following management command:

manage.py remove_stale_contenttypes
@jeremystretch commented on GitHub (Nov 28, 2018): This is happening because we delete the InterfaceConnection model and then introduce a new InterfaceConnection _proxy_ model in the `0066_cables` DCIM migration under v2.5. For reference: v2.4.8: ``` netbox=> select * from auth_permission where codename like '%interfaceconnection%'; id | name | content_type_id | codename -----+---------------------------------+-----------------+---------------------------- 112 | Can add interface connection | 38 | add_interfaceconnection 113 | Can change interface connection | 38 | change_interfaceconnection 114 | Can delete interface connection | 38 | delete_interfaceconnection (3 rows) ``` After migrating to v2.5-beta2: ``` netbox=> select * from auth_permission where codename like '%interfaceconnection%'; id | name | content_type_id | codename -----+---------------------------------+-----------------+---------------------------- 112 | Can add interface connection | 38 | add_interfaceconnection 113 | Can change interface connection | 38 | change_interfaceconnection 114 | Can delete interface connection | 38 | delete_interfaceconnection 315 | Can add interface connection | 37 | add_interfaceconnection 316 | Can change interface connection | 37 | change_interfaceconnection 317 | Can delete interface connection | 37 | delete_interfaceconnection 318 | Can view interface connection | 37 | view_interfaceconnection (7 rows) ``` So there are actually two issues here: 1. The content type and permissions for the old InterfaceConnection model aren't getting deleted along with the model. This appears to be normal Django behavior, but we can accomplish this manually in the migration. 2. The new proxy console/power/interface connection models are getting add/change/delete permissions created for them, which are unnecessary and unusable. I'll open a new issue for this second point. In the meantime, this can be resolved by cleaning out stale content types with the following management command: ``` manage.py remove_stale_contenttypes ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2156