question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace numeric constants with slug values

See original GitHub issue

Proposed Changes

Replace the numeric values used for many fields with human-friendly slug values. For example:

RACK_STATUS_RESERVED = 0
RACK_STATUS_AVAILABLE = 1
RACK_STATUS_PLANNED = 2
RACK_STATUS_ACTIVE = 3
RACK_STATUS_DEPRECATED = 4
RACK_STATUS_CHOICES = [
    [RACK_STATUS_ACTIVE, 'Active'],
    [RACK_STATUS_PLANNED, 'Planned'],
    [RACK_STATUS_RESERVED, 'Reserved'],
    [RACK_STATUS_AVAILABLE, 'Available'],
    [RACK_STATUS_DEPRECATED, 'Deprecated'],
]

would become

RACK_STATUS_RESERVED = 'active'
RACK_STATUS_AVAILABLE = 'planned'
RACK_STATUS_PLANNED = 'reserved'
RACK_STATUS_ACTIVE = 'available'
RACK_STATUS_DEPRECATED = 'deprecated'
RACK_STATUS_CHOICES = [
    [RACK_STATUS_ACTIVE, 'Active'],
    [RACK_STATUS_PLANNED, 'Planned'],
    [RACK_STATUS_RESERVED, 'Reserved'],
    [RACK_STATUS_AVAILABLE, 'Available'],
    [RACK_STATUS_DEPRECATED, 'Deprecated'],
]

Justification

Employing human-friendly slug values make consuming the REST API more convenient. It also allows more human-friendly representations of the pertinent field values in other formats, such as YAML (see #451).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:36 (33 by maintainers)

github_iconTop GitHub Comments

6reactions
jeremystretchcommented, Nov 6, 2019

After giving this some more thought, I’m going to proceed with option 3 as it seems like the best compromise between developer and user maintainability. The value field will convey the new slug value, and we’ll add an id field to continue conveying the numeric value (to be deprecated for v2.8).

"status": {
    "value": "active",
    "id": 1,
    "label": "Active"
}

Importantly, these fields will accept both the numeric and slug values on write for the entire v2.7 release, to maintain backward compatibility for the near future.

3reactions
tyler-8commented, Oct 18, 2019

The problem still lies in the transition of dependent-services. If the solution is to “wait until everything supports the new scheme” then that means the release of N-number of new versions external scripts/apps/services at the exact same time as the Netbox upgrade. That’s untenable for most environments.

to @lampwins point, if there was some sort of API versioning in place, for example v2.7.0 provided these two endpoints:

/api/dcim/interfaces/
/api/v2/dcim/interfaces/

That would allow each individual external app/service/script to migrate in its own time, on separate release windows from the Netbox upgrade. This is a far better experience all around and makes the upgrade process much easier to go through.

From a maintainer perspective, really it’s just a separate API module at that point, the code for the two shall remain separate - and you only move new code to the api_v2.py module when there’s actually a v2 - keeping it clear where things are.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to convert a Title to a URL slug in jQuery? - Stack Overflow
I have no idea where the 'slug' term came from, but here we go: function convertToSlug(Text) { return Text.toLowerCase() .replace(/ /g ...
Read more >
Slug - Sanity.io
A schema type for slugs, typically used to create unique URLs.
Read more >
BigBinary Books - Optimizing slug generation process
One solution here is to use the LIKE operator from SQLite to query all tasks with a matching slug. Once we have a...
Read more >
Store Variables with the TI-84 Plus Calculator - Dummies.com
Learn how to store variables in a TI-84 Plus calculator by using the STO key. Here's a step-by-step guide, with screen images.
Read more >
replace - Functions - Configuration Language | Terraform
The replace function searches a given string for another given substring, and replaces all occurrences with a given replacement string.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found