mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-13 22:03:32 +01:00
Remove slugs from all models #5759
Closed
opened 2025-12-29 19:32:15 +01:00 by adam
·
24 comments
No Branch/Tag Specified
main
21050-device-oob-ip-may-become-orphaned
21102-fix-graphiql-explorer
20911-dropdown
20239-plugin-menu-classes-mutable-state
21097-graphql-id-lookups
feature
fix_module_substitution
20923-dcim-templates
20044-elevation-stuck-lightmode
feature-ip-prefix-link
v4.5-beta1-release
20068-import-moduletype-attrs
20766-fix-german-translation-code-literals
20378-del-script
7604-filter-modifiers-v3
circuit-swap
12318-case-insensitive-uniqueness
20637-improve-device-q-filter
20660-script-load
19724-graphql
20614-update-ruff
14884-script
02496-max-page
19720-macaddress-interface-generic-relation
19408-circuit-terminations-export-templates
20203-openapi-check
fix-19669-api-image-download
7604-filter-modifiers
19275-fixes-interface-bulk-edit
fix-17794-get_field_value_return_list
11507-show-aggregate-and-rir-on-api
9583-add_column_specific_search_field_to_tables
v4.5.0
v4.4.10
v4.4.9
v4.5.0-beta1
v4.4.8
v4.4.7
v4.4.6
v4.4.5
v4.4.4
v4.4.3
v4.4.2
v4.4.1
v4.4.0
v4.3.7
v4.4.0-beta1
v4.3.6
v4.3.5
v4.3.4
v4.3.3
v4.3.2
v4.3.1
v4.3.0
v4.2.9
v4.3.0-beta2
v4.2.8
v4.3.0-beta1
v4.2.7
v4.2.6
v4.2.5
v4.2.4
v4.2.3
v4.2.2
v4.2.1
v4.2.0
v4.1.11
v4.1.10
v4.1.9
v4.1.8
v4.2-beta1
v4.1.7
v4.1.6
v4.1.5
v4.1.4
v4.1.3
v4.1.2
v4.1.1
v4.1.0
v4.0.11
v4.0.10
v4.0.9
v4.1-beta1
v4.0.8
v4.0.7
v4.0.6
v4.0.5
v4.0.3
v4.0.2
v4.0.1
v4.0.0
v3.7.8
v3.7.7
v4.0-beta2
v3.7.6
v3.7.5
v4.0-beta1
v3.7.4
v3.7.3
v3.7.2
v3.7.1
v3.7.0
v3.6.9
v3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-r1
v1.0.3
1.0.0
Labels
Clear labels
beta
breaking change
complexity: high
complexity: low
complexity: medium
needs milestone
netbox
pending closure
plugin candidate
pull-request
severity: high
severity: low
severity: medium
status: accepted
status: backlog
status: blocked
status: duplicate
status: needs owner
status: needs triage
status: revisions needed
status: under review
topic: GraphQL
topic: Internationalization
topic: OpenAPI
topic: UI/UX
topic: cabling
topic: event rules
topic: htmx navigation
topic: industrialization
topic: migrations
topic: plugins
topic: scripts
topic: templating
topic: testing
type: bug
type: deprecation
type: documentation
type: feature
type: housekeeping
type: translation
Mirrored from GitHub Pull Request
No Label
type: deprecation
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/netbox#5759
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jeremystretch on GitHub (Dec 10, 2021).
Proposed Changes
Remove the
slugfield from all models which have one. Any filters which reference the slug field will be modified to reference the object's name instead.Justification
Slugs were phased out of use in URLs under #6097 and no longer serve any real purpose. NetBox users who utilize this field to store data should switch to using a custom field.
@DanSheps commented on GitHub (Dec 10, 2021):
I would have to double check, but I do believe we use slugs in a few filters as a way to query (?role=xxx vs ?role_id=###)
This might be impactful for API reasons and we might want to look at that more carefully.
@DanSheps commented on GitHub (Dec 10, 2021):
Thinking about this more...
I would have to vote against this. The recommendation for switching to custom fields, I feel, is too burdensome on the user. Custom fields aren't a "hard" field with specific requirements:
If some of these are addressable, maybe we mark this as blocked until we can implement those workarounds?
@rodvand commented on GitHub (Dec 10, 2021):
I know the ansible modules heavily uses slugs for its functionality. So removing them would require a rework on the modules.
@jeremystretch commented on GitHub (Dec 10, 2021):
Does it? Only if you have a specific need to store a slug for an object in the first place, which I would guess most users do not.
As slugs are no longer used in URLs, there's really no need for them to be unique (or to exist at all).
This is true for slugs as well: You can't assume that a slug is known ahead of time. You might be able to guess it 99% of the time, but that's not good enough to avoid querying entirely.
Same as above. The argument is predicated on knowing the slug ahead of time, which is not reasonable.
You would access it as
site__custom_field_data__slug. I don't see a significant distinction.Sure, and I think that's a reasonable one-time request to ditch a significant amount of unnecessary overhead. On the flip side, users who don't need slugs will never again be forced to populate them when creating objects.
It's worth pointing out that only 21 or around 80 models currently have a slug field. So, presumably, we can simply standardize on those what we do for the others. Ultimately this should reduce code and make the library easier to maintain in general.
@kkthxbye-code commented on GitHub (Dec 10, 2021):
I'm voting for. Slugs are for URL's, and if they are not used for URL's anymore, remove them.
If you know what object you want without lookup, just use the id.
@DanSheps commented on GitHub (Dec 11, 2021):
Technically not correct, a slug is a URL friendly label:
Source
We use them in URLs but that isn't all they are.
ID's are not always fixed, generally slugs are.
@kkthxbye-code commented on GitHub (Dec 11, 2021):
I'm not going engage in an argument based on the etymology of a word. How we use slugs in netbox should be all that matters.
https://en.wikipedia.org/wiki/Clean_URL#Slug
How can you change a pk in netbox from the UI or API without creating a new object? Are there any instances where you could see a valid reason to change the pk of an object? Essentially pk's are more static than slugs, because slugs can be changed at will.
@jeremystretch commented on GitHub (Dec 11, 2021):
There's a compromise approach as well: We can just make slugs optional fields for now. This will at least alleviate the burden of having to define slugs that are otherwise unused, without interfering with those that are. I'd still like to eventually remove slugs completely, but this can happen at a later point in the future.
@sol1-matt commented on GitHub (Dec 11, 2021):
I am voting against. I think removing slugs from Netbox is a bad idea. The reasons for this are
Slugs are incredibly useful in any sort of automation compared with
nameorid. The types of automation I've had experience with are monitoring (Icinga), Ansible and other custom glue scripts that exchange data between Netbox and other sources.Because slugs are automatically generated it makes it less likely humans will do something to break linked systems they don't know or care about, automatic slug creation does the work for them. Not having the slug created automatically at data entry time means the user needs to perform work previously done automatically and in the case of using a custom field as a replacement the linked object no longer shares the same value.
Having a automatically generated computer friendly, default
/[a-z]-_/, unique value as a reference in the source or truth makes using that data in other systems easy to do. Being able to reference a site by slug, egexampleorsite_example, is has benefits over id,123orsite_123. Both Icinga and Ansible benefit from slugs, Icinga because monitoring object names that contain the slug over id are instantly recognisable to the humans who manage monitoring, Ansible for the same reason as group names that use the slugs are referenced in playbooks so- host: site_exampleis much more readable than- host: site_123The name of an object isn't a adequate replacement for slug, names are case sensitive and can have a much wider range of characters. The slug creation in Netbox simplifies the name (automatically) but will alert the user to problems only if found. It is particularly good a picking up objects with the same name but different case. There are 2 benefits to this a) Netbox is less likely to have bad or confusing data like the same server entered twice or assigned the same name and b) external system can trust the uniqueness of Netbox data.
Currently slugs are used as a reference between objects and are useful over id's. If in external systems we want to reference a devices site the slug between the 2 can be used. Monitoring and automation systems tend to be configuration based, not code based and as such humans will want to read the configuration,
import site_exampleis easier to understand thanimport site_123External systems replicating slugs on the way in
There are individual problems with this but the main effect is Netbox data is less truthful. Some of the individual problems introduced because Netbox no longer has slugs is
External slug creation errors due to duplicates or other human error gets moved from data entry time to export time.
External systems that import Netbox objects independently, ie 1 object type only, will only have the
idas a link as thenamepart only exists on one side so a slug can only be created on one side, not both unless they are imported already linked.External systems that import only one object type at a time that load linked objects to recreate slugs dramatically increase load, 2500 devices = 3 api calls now vs 3 api call + 2500 api calls per linked object or just load everything from all linked objects.
External systems that read data from Netbox and then later use that data to enhance data in Netbox will need to store Netbox specific references for the object that are seperate from the externally generated slug replacement because Netbox will no longer have any idea on what the object is.
@sol1-matt commented on GitHub (Dec 11, 2021):
Optional as in a setting that is
REQUIRE_SLUGS = TRUEor optional as in doesn't need to be filled out?If it doesn't need to be filled out is it still filled out automatically?
Edit: Could we get some more examples of the problems slugs create, perhaps there is a different solution rather than removing slugs all together.
@jeremystretch commented on GitHub (Dec 11, 2021):
Only when creating objects via the UI. There is no automation when using the REST API.
As would be a custom field that replaces it.
I can't think of any instances where this is true. Uniqueness is enforced for both name and slug consistently for each model. They are redundant.
There are no inter-object relationships in NetBox which depend on the slug field. It was only ever used in URLs (gone in v2.11) and filter sets.
@sol1-matt commented on GitHub (Dec 11, 2021):
This is true, but I trust developers more than I trust users and it is generally easier to find the developers and tell them to change the code than retrain users
the custom field only exists on one side of a object, a site slug custom field would only exist on the site, the device wouldn't have any idea of what the site slug custom field is from itself it needs the id for that and if you are loading the whole site but using the site stub on the device object there is a problem
Case is the big one for uniqueness, slug is good at telling the user when they have been dumb and entered a duplicate with different case aka FooBar and Foobar. Some external systems are case insensitive and slug is a lifesaver when it comes to using Netbox as a source of truth for them.
I agree with that, but I wasn't referencing Netbox but other systems that use Netbox as a source of truth that recreate objects in their own way. Netbox's model approach translates well so it get replicated :)
Thinking about this more the benefits slugs give external applications might be resolved by allowing rules to be set around
name. That way the cost of slugs could be removed but the benefits (a trusted field users can't screw up) could be retained, win-win.@sol1-matt commented on GitHub (Dec 11, 2021):
19 minutes worth of though so this might be brilliant or terrible.
A number of the benefits of
slugthat make Netbox useful as a source of truth to external applications exists with thenamefield.Being able to configure the
namefield to allow administrators to configure what can be entered (case insensitive unique, starts with a S, no vowels, etc...) would make thenamefield a good replacement for slug when needed.Allowing multiple rule sets that could be applied at both the object level and objects role/group level would help prevent the problems that currently exist with
slugbeing migrated toname.@kkthxbye-code commented on GitHub (Dec 11, 2021):
Slug uniqueness is case sensitive afaik, so that's not even true.
@DanSheps commented on GitHub (Dec 11, 2021):
Certain transactions can cause PK's to change. Certain types of replication could cause PK's to change.
A slug defined by you will always be the same unless it is changed by you.
This is only sort of true. It is true if you accept the default auto-generated slug. Not so true if you edit the slug after it is auto-generated.
I think perhaps having slug optional would be the way to go. Maybe even adding the ability to turn off display of slug in the configuration might be best.
@kkthxbye-code commented on GitHub (Dec 11, 2021):
On models with slugs? Do you have an example?
As opposed to the name?
Like replicating the database somewhere else and changing the pk's when doing it? If so, how is that relevant?
@sol1-matt commented on GitHub (Dec 11, 2021):
@kkthxbye-code Automatic slug creation is lowercase , the user can go out of their way to change the slug but it does tell you when you create a duplicate name with different case initially.
From https://demo.netbox.dev/
@sol1-matt commented on GitHub (Dec 11, 2021):
@jeremystretch has just pointed out custom validators.
I'm going to try and replace the functionality existing with slug with custom validators and name for external applications using Netbox as a source of truth next week.
@sol1-matt commented on GitHub (Dec 14, 2021):
TL;DR Can custom validators be used to ensure the name field is a suitable replacement for slug's in external applications? yes
I've done some testing of custom validators to see if the functionality of the slug for external applications can be duplicated with the name field. I think it is possible with validators.
This is an example of a validator I created
What does this buy me
External applications that use Netbox as a source of truth may want to slugify the name for it's own purposes, eg: ansible groups should be '^[a-z0-9_]*$'. But custom validators allow Netbox and the Netbox user to ensure the data at entry time can match pretty much any rules you can think of.
@DanSheps commented on GitHub (Dec 15, 2021):
While this works for the name field, it doesn't address the fact that you might want your name field to be different then the slug. I am sure you can custom validate on slugs to, however I think a more measured approach would be to instead make the slug field optional as Jeremy mentioned. That solves both problems. If we truely want to disable the slug field, also hiding it with a config variable might be an option.
ETA: I think we would need more data to determine how slugs are being used before we consider removing them completely. We can probably put a few questions in the user survey regarding slugs.
@sol1-matt commented on GitHub (Dec 16, 2021):
You can make the
nameaslugfor external applications, or at least create a safeslugfrom thename. The validator can be abused quite nicely to ensure users can't enter the wrong thing either.The slug field currently has a couple of features that are useful
If the slug field becomes optional what is the behavior for ON?
For instance if an optional slug doesn't appear on linked objects the usefulness drops dramatically for some external applications.
This is why I'm suggesting the
namefield with validation is a slug replacement for those that need it (such as myself). With custom validationnamecan be made better than current slugs.@DanSheps commented on GitHub (Dec 17, 2021):
By validating on name, you are decreasing the usefulness of the name field though, and you may have instances where the name needs the character that isn't available in the slug character limit
@candlerb commented on GitHub (Dec 18, 2021):
I'd like to make a completely off-field counter-proposal, which I'll call "embrace the slug". The principles are:
At this point the slug is just another ID, like the sequential numeric ID. The big difference is that it can be understood across systems.
This form of ID allows some things which are not possible today:
And there are some things which would be possible today with numeric IDs, but which work better with slugs:
[^1] The only exception might be things which have mandatory and globally unique names, e.g. tags.
[^2] This also allows globally unique references to be formed, as
<object-type>:<slug>. Essentially this is how Salesforce object IDs work.[^3] Slugs are most powerful when GUIDs, and lose their inter-system uniqueness properties if selected manually. When creating objects via the web UI, you could allow the user to select a slug, or even pick a default as today, e.g. based on the name, plus a suffix if it already exists. However, I'm leaning towards making slugs be GUIDs always.
[^4] Not necessarily impossible, but it should be discouraged, and hard to do by default. In particular, the "edit" page for an object should leave the slug field non-editable by default. If slugs are GUIDs then there should be no reason at all to change them.
@jeremystretch commented on GitHub (Dec 19, 2021):
I don't think this is worth discussing any further. Although I disagree with all the counterpoints raised in favor of retaining slugs, there's clearly a substantial amount of dissent, so we're not going to remove them completely at this time.
As a potential compromise between those users who rely on slugs and those who perceive them as a burden, I've proposed in #8113 that we alter all slug fields to no longer be required fields. Users are encourage to provide feedback. Hopefully this proposal will prove to be less contentious.