Device object Allowed Create Without Slug
See original GitHub issueEnvironment
- Python version:
- Nautobot version:
Steps to Reproduce
- 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)
- Execute Job
- 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<slug>[-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<slug>[-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:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 callingsave()
, or callvalidated_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