Permission constraints for dcim.device require int value for device_type (not just device_type_id) #11521

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

Originally created by @dpotter-intoto on GitHub (Aug 22, 2025).

Deployment Type

Self-hosted

NetBox Version

v4.3.6

Python Version

3.11

Steps to Reproduce

  1. Click Admin>Add Permission
  2. Create new Permission
  3. Select DCIM.device
  4. Add constraint syntax {"device_type": "test"}
  5. Click Create
    Observe error: Invalid filter for <class 'dcim.models.devices.Device'>: Field 'id' expected a number but got 'test'.

Expected Behavior

Constraint should allow filters on device_type by slug.
Constraint should allow string logic operators (e.g., __regex, __iew)

Observed Behavior

Error thrown: Invalid filter for <class 'dcim.models.devices.Device'>: Field 'id' expected a number but got 'test'.

Originally created by @dpotter-intoto on GitHub (Aug 22, 2025). ### Deployment Type Self-hosted ### NetBox Version v4.3.6 ### Python Version 3.11 ### Steps to Reproduce 1. Click Admin>Add Permission 2. Create new Permission 3. Select DCIM.device 4. Add constraint syntax `{"device_type": "test"}` 5. Click `Create` Observe error: `Invalid filter for <class 'dcim.models.devices.Device'>: Field 'id' expected a number but got 'test'. ` ### Expected Behavior Constraint should allow filters on device_type by slug. Constraint should allow string logic operators (e.g., __regex, __iew) ### Observed Behavior Error thrown: `Invalid filter for <class 'dcim.models.devices.Device'>: Field 'id' expected a number but got 'test'. `
adam added the netbox label 2025-12-29 21:46:22 +01:00
adam closed this issue 2025-12-29 21:46:22 +01:00
Author
Owner

@DanSheps commented on GitHub (Oct 6, 2025):

I don't think this is valid.

The proper constraint should be: {"device_type__slug": "test"} I believe. @dpotter-intoto I would give that a try.

Edit: Confirmed, this is not a bug.

@DanSheps commented on GitHub (Oct 6, 2025): I don't think this is valid. The proper constraint should be: `{"device_type__slug": "test"}` I believe. @dpotter-intoto I would give that a try. Edit: Confirmed, this is not a bug.
Author
Owner

@dpotter-intoto commented on GitHub (Oct 6, 2025):

@DanSheps Thank you for the helpful suggestion and test. I will certainly proceed with your recommendation.

I was thrown by the list of supported fields suggested in the UI when adding a permission constraint. This list includes device_type, not not device_type_slug.

Invalid filter for <class 'dcim.models.devices.Device'>: Cannot resolve keyword 'device_type_junk' into field. Choices are: airflow, asset_tag, bookmarks, cabletermination, cluster, cluster_id, comments, config_template, config_template_id, console_port_count, console_server_port_count, consoleports, consoleserverports, contacts, created, custom_field_data, description, device_bay_count, device_type, device_type_id, devicebays, ...

Should I reopen this issue as a request to align the prompt in the UI with the actually-supported constraints?

Image
@dpotter-intoto commented on GitHub (Oct 6, 2025): @DanSheps Thank you for the helpful suggestion and test. I will certainly proceed with your recommendation. I was thrown by the list of supported fields suggested in the UI when adding a permission constraint. This list includes `device_type`, not not `device_type_slug`. `Invalid filter for <class 'dcim.models.devices.Device'>: Cannot resolve keyword 'device_type_junk' into field. Choices are: airflow, asset_tag, bookmarks, cabletermination, cluster, cluster_id, comments, config_template, config_template_id, console_port_count, console_server_port_count, consoleports, consoleserverports, contacts, created, custom_field_data, description, device_bay_count, device_type, device_type_id, devicebays, ... ` Should I reopen this issue as a request to align the prompt in the UI with the actually-supported constraints? <img width="702" height="562" alt="Image" src="https://github.com/user-attachments/assets/768239d3-162a-4160-99e0-559e0b15e6d6" />
Author
Owner

@DanSheps commented on GitHub (Oct 6, 2025):

You need to include two underscores. This is a Django convention, with the permission constraints you are basically building raw database queries.

Please review the permission constraints documentation for more information.

Do not open another issue for this, it is already documented in the documentation

@DanSheps commented on GitHub (Oct 6, 2025): You need to include two underscores. This is a Django convention, with the permission constraints you are basically building raw database queries. Please review the permission constraints documentation for more information. Do not open another issue for this, it is already documented in the documentation
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11521