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.

Device object Allowed Create Without Slug

See original GitHub issue

Environment

  • Python version:
  • Nautobot version:

Steps to Reproduce

  1. Create a job that executes a get_or_create() without a slug
        for device_role in ["Firewall"]:
            DeviceRole.objects.get_or_create(name=device_role)
  1. Execute Job
  2. Navigate to DCIM>Device Roles

Get reverse match error:

<h1>NoReverseMatch
       at /dcim/device-roles/</h1>
  <pre class="exception_value">Reverse for 'devicerole' with arguments '('',)' not found. 1 pattern(s) tried: ['dcim\\/device\\-roles\\/(?P&lt;slug&gt;[-a-zA-Z0-9_]+)\\/$']</pre>
  
Request Method: | GET
-- | --
http://[::]:8080/dcim/device-roles/
3.1.11
NoReverseMatch
Reverse for 'devicerole' with arguments '('',)' not found. 1 pattern(s) tried: ['dcim\\/device\\-roles\\/(?P&lt;slug&gt;[-a-zA-Z0-9_]+)\\/$']
/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py, line 685, in _reverse_with_prefix
/usr/local/bin/python
3.6.13
['/usr/local/bin',  '/usr/local/lib/python3.6/site-packages/git/ext/gitdb',  '/usr/local/lib/python36.zip',  '/usr/local/lib/python3.6',  '/usr/local/lib/python3.6/lib-dynload',  '/root/.local/lib/python3.6/site-packages',  '/usr/local/lib/python3.6/site-packages',  '/source',  '/usr/local/lib/python3.6/site-packages/gitdb/ext/smmap']
Wed, 26 May 2021 14:54:48 +0000


Expected Behavior

If slug is required then there should be an error on the Job execution

Observed Behavior

Allowed the creation of a Device Role without the slug, causing an error.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
jathanismcommented, May 26, 2021

Ideally it would be nice if any create function would handle the slug creation on its own if not supplied, similar to how the UI handles it.

I do agree with this sentiment. Having slugs auto-populate at the model level like they do in the web UI forms would be a nice thing to add for model validation and go some of the way to avoiding this heartache.

1reaction
jathanismcommented, May 26, 2021

This is working as intended and is not a problem with Nautobot unfortunately.

Because model validation isn’t enforced at the ORM. You have to create an instance, then call full_clean() on the instance before calling save(), or call validated_save() (which is a custom thing we added that does both).

If you’re gonna be blacksmithing objects manually from the ORM, it’s a good idea to get into the habit of doing this!

Further reading: https://docs.djangoproject.com/en/3.2/ref/models/instances/#validating-objects

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django DeleteView without slug and via POST - Stack Overflow
First of all, your sample code has various problems which need to be fixed: The input type should be hidden , not hiden...
Read more >
What's a slug. and why would I use one? | by Dave Sag | ITNEXT
A slug is a human-readable, unique identifier, used to identify a resource instead of a less human-readable identifier like an id .
Read more >
Pynetbox - NetBox Python API client part 2 - creating objects |
Welcome to the second post in the series dedicated to Pynetbox, Python API client for NetBox. In this episode I'll be talking about...
Read more >
How to replace the Strapi ID field with a slug field - YouTube
This allows your url path slug to dictate which content is returned from Strapi and is useful when creating blogs with Strapi.
Read more >
Are Slugs Harmful? - Terro
Slugs are land-dwellers in the mollusk's family, snails are a close cousin. Their slime allows them to move around freely sharp objects even...
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