Replies: 7 comments 6 replies
-
Workaround:
...
(Note: Site already has a globally unique name, so the slug logic will rarely find conflicts. But it will if you had one site called "foobar" and another called "FooBar" or "foo@bar", for example) |
Beta Was this translation helpful? Give feedback.
-
I didn't get time to read your proposal thoroughly but just to point out, slugs are displayed on the object views in the top right corner of the model supports it |
Beta Was this translation helpful? Give feedback.
-
I personally would eliminate slugs altogether. Objects already have (per-device model) unique identifier. I personally never use slugs in the scripts that I write, except when I have to generate them to satisfy the API (I may switch to just generating a UUID instead of duplicating the name-to-slug javascript code). |
Beta Was this translation helpful? Give feedback.
-
I use slugs, to make the API call or URL more readable, when composing DNS compatible names, or when building a hash/dictionary of items to normalize existence checks when comparing with other IT systems, eg. the "Basketweaving Department" building is going to be "basketweaving" in DNS and other IT systems, which is easily represented by the slug, so auditing "switch01-basketweaving-access" device makes sense or referencing /dcim/devices/?site=basketweaving instead of ?site_id=3. Kind of like how export CSV and import CVS are different because human-readable and machine-readable representations are a little different.
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: Jeffrey C. Ollie ***@***.***>
Sent: Friday, April 21, 2023 10:09 AM
To: netbox-community/netbox ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [netbox-community/netbox] Revisit slugs (Discussion #12315)
I personally would eliminate slugs altogether. Objects already have (per-device model) unique identifier. I personally never use slugs in the scripts that I write, except when I have to generate them to satisfy the API (I may switch to just generating a UUID instead of duplicating the name-to-slug javascript code).
—
Reply to this email directly, view it on GitHub<#12315 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM7ANZHWLF5LYIVTIATXCKPMHANCNFSM6AAAAAAXGYYWPQ>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I don't "use" slugs. They can be modified on the fly so I don't see them useful for linking between systems or documents. The NetBox GUI-autogenerated slugs are also not visually compatible with non-English strings ("Ääliö, älä lyö, ööliä läikkyy" -> "li-l-ly-li-likkyy"). But, when they are mandatory, all my apps just generate them as a random 8-character strings. |
Beta Was this translation helpful? Give feedback.
-
BTW, I came across a case where slugs aren't globally unique: device types. It's only the (manufacturer,slug) combination which is unique. That makes the slug not directly usable as a slug. It would be more consistent IMO if device type slugs were forced to be unique, even if they had to be e.g. "cisco-ncc-1701" and "ufp-ncc-1701" for two manufacturers with a model "ncc-1701". |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I'd like to bring up the issue of slugs again, as a follow-up to #8113 (closed). I'm raising this as a discussion for now, but will reformat as formal feature request(s) if there's any chance of it being accepted.
The main inconvenience with slugs is that they are mandatory: e.g. when creating a site via the API, if you don't provide one, you get
django.core.exceptions.ValidationError: {'slug': ['This field cannot be blank.']}
. Hence you need to duplicate the slug-synthesis logic (which currently sits in Javascript) in Python.And yet, whilst being so "important" that they are mandatory, they are not even shown in the UI, e.g.(They are shown in light grey, at top right corner; just not in the main attributes table)/dcim/sites/123/
doesn't show the slug (although the "Edit" page does)Part 1
My outline proposal is:
At this point, if you choose to use slugs, they are still valid as alternate unique keys (for those models that have them anyway).
I notice there are a handful of places where slugs are used in HTML templates:
These would have to be changed to use ids - e.g.
provider_id={{ object.id }}
instead ofprovider={{ object.slug }}
, to ensure they work for providers without slugs.Alternatively, slugs could remain mandatory for a few models. I note that tags are especially awkward to use without slugs. (I don't think anyone wants to write a REST API call with
?tag_id=123
when they could use?tag=snmp
)Part 2
As a separate feature request, I'd like to see that the CSV/YAML upload accepts slugs as well as Netbox sequential IDs as a way to do upserts. That is: if you provide a slug (but not an ID) and there's an existing record with that slug, it gets updated instead of creating a new one. Since slugs already exist for some models and are already unique, this is an independent FR.
Part 3
Add slugs, in the same optional form, to all other models - e.g. Device. This makes them useful for syncing records between systems - you can choose to put in a UUID for instance - but since they're optional, nobody who doesn't want them is inconvenienced in any way. For completeness, allow filters like
device=<slug>
as well asdevice_id=<id>
Whether or not you accept part 2 or part 3, I think part 1 stands on its own.
[^1] Ideally, there would be some pluggable pre-save logic to auto-create slugs. Then you could plug in the existing logic to derive a slug from the name, or generate a UUID, or whatever you want. I'm not sure if custom validators are allowed the modify the model they are validating.
In the Edit page, the slug should not be changed unless explicitly edited - but that's already the case today.
Having a button next to the slug field, to auto-fill it using the existing Javascript logic, might also help people who like the current arrangement.
Alternative
As an alternative to address the API inconvenience: if slugs stay as they are today, then I'd suggest adding the auto-slug-creation logic to the models to be used when the slug is empty. In this way, if you try to create a site but don't provide a slug, it will supply one for you. In the case of a conflict, it would have to use
<slug>-<suffix>
.Beta Was this translation helpful? Give feedback.
All reactions