Netbox: Don't change slug if already exists/populated

Created on 30 Dec 2019  Â·  4Comments  Â·  Source: netbox-community/netbox

Environment

  • Python version: 3.6.5
  • NetBox version: v2.6.9

Proposed Functionality

When editing an item's name (site, device, ...) with slugs already populated, the javascript shouldn't automatically regenerate and clobber the existing slug. Would be nice to include a refresh (↺) icon next to the slug name for those who do want the slug to update with the generated value.

Use Case

Updating the slug on the edit pages breaks any shared links (i.e. from a wiki page for documentation) or breaks the already chosen slug format (imported data including a slug). My use case is an already existing database in which we imported the data. But any typo's in the name that were discovered or when the site name changes (rare but acquisitions do happen) causes the per-determined slug to be invalidated. With my current employer and my previous employer, for sites alone this is well in excess of 100+, and 75+ for multi-hierarchy regions.

Generating the slug makes complete sense when creating an ad-hoc entry, but not editing an existing one IMHO.

Database Changes

None

External Dependencies

AFAICT, none

accepted

Most helpful comment

Disabled auto-reslugification for existing objects and added a button to manually regenerate it:

edit_site_slug

All 4 comments

But any typo's in the name that were discovered or when the site name changes (rare but acquisitions do happen) causes the per-determined slug to be invalidated.

But that means correcting the name automatically corrects the slug, right? I wouldn't think you'd want to keep the erroneous slug. Yes, it means updating any referring links from external sources, but that's the cost of not validating data prior to import.

Fair point. However I don't feel that it invalidates the 2nd portion in which slugs are generated on import. Re-reading my initial request I seem to have not communicated this well.

I set many of the slugs because we already had uniqueness and it's required for import. For example, device roles I had 'Edge fabric switch'='efs' instead of 'edge-fabric-switch', Sites already had small site codes 'Equinix DA2'='EQ-DA2'. Automatically updating the slug (even by accident) seems to have undesirable results for me.

Being it's all in the javascript, I'm assuming it isn't something we can create a config setting for unfortunately.

But that means correcting the name automatically corrects the slug, right? I wouldn't think you'd want to keep the erroneous slug.

In my case, I do want to keep the original ("erroneous") slug.

I am planning to use the slug as a stable reference for another system. If the user-readable description is changed, I want the slug to be kept the same.

I think the solution could be as simple as:

  • When creating a new device role, site, rack etc: auto-populate the slug as you type (*)
  • But when editing an existing record, don't update the slug. The user can still change it if they wish.

(*) Or even more simply: you could leave the field empty in the UI. On save, if the slug is empty, then auto-generate one. If there is a conflict with existing slug, the record will fail to save.

This also has the benefit that if you want to "reset" the slug you can just set it to empty field and save; no need for a "refresh" button.

Disabled auto-reslugification for existing objects and added a button to manually regenerate it:

edit_site_slug

Was this page helpful?
0 / 5 - 0 ratings

Related issues

soer7022 picture soer7022  Â·  3Comments

luto picture luto  Â·  3Comments

aarjbdea picture aarjbdea  Â·  3Comments

VictorJ76 picture VictorJ76  Â·  3Comments

hoalex picture hoalex  Â·  3Comments