Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a weird error message when trying to create device type #471

Open
mickmortensen opened this issue Jun 13, 2022 · 4 comments
Open
Labels
pynetbox status: under review Further discussion is needed to determine this issue's scope and/or implementation

Comments

@mickmortensen
Copy link

When trying to execute the following code:
model = 'DCS-7280SR-48C6'
nb.dcim.device_types.create([{
"model": model,
"manufacturer": 3,
"slug": model.lower()
}])

I get the following error:
The request failed with code 400 Bad Request: [{'non_field_errors': ['The fields manufacturer, model must make a unique set.', 'The fields manufacturer, slug must make a unique set.']}]

But the object gets created in netbox, so what does the error mean?
The plan is to create device types on in a for loop, this is just an example which throws the same error.
Running pynetbox version 6.6.2 and Netbox version 3.2.3

@jeremystretch
Copy link
Member

It sounds like the request is being sent to NetBox twice, but I'm not sure why that would happen.

@markkuleinio
Copy link
Contributor

markkuleinio commented Jun 13, 2022

Works for me (lines split for readability):

>>> pynetbox.__version__
'6.6.2'
>>> nb.status()["netbox-version"]
'3.2.4'
>>> list(nb.dcim.device_types.filter())
[Generic]
>>> nb.dcim.device_types.create([{"model": "Model1", "manufacturer": 1, "slug": "model1"}])
[Model1]
>>> list(nb.dcim.device_types.filter())
[Generic, Model1]
>>> nb.dcim.device_types.create([{"model": "Model2", "manufacturer": 1, "slug": "model2"}])
[Model2]
>>> list(nb.dcim.device_types.filter())
[Generic, Model1, Model2]
>>> nb.dcim.device_types.create([{"model": "Model2", "manufacturer": 1, "slug": "model2"}])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/markku/devel/pynetbox/venv/lib/python3.7/site-packages/pynetbox/core/endpoint.py", line 318, in create
    ).post(args[0] if args else kwargs)
  File "/home/markku/devel/pynetbox/venv/lib/python3.7/site-packages/pynetbox/core/query.py", line 399, in post
    return self._make_call(verb="post", data=data)
  File "/home/markku/devel/pynetbox/venv/lib/python3.7/site-packages/pynetbox/core/query.py", line 287, in _make_call
    raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request:
[{'non_field_errors':
  ['The fields manufacturer, model must make a unique set.', 'The fields manufacturer, slug must make a unique set.']
}]
>>> list(nb.dcim.device_types.filter())
[Generic, Model1, Model2]
>>>

@mickmortensen
Copy link
Author

mickmortensen commented Jun 13, 2022

Used requests for that one part of my script since i have no idea why that error appears, if i just run:
model = 'DCS-7280SR-48C6'
nb.dcim.device_types.create([{
"model": model,
"manufacturer": 3,
"slug": model.lower()
}])
I get the error, and if i run it in a loop i get it as well (Ran it in the python IDE, since i suspected the loop was the thing causing the issue), so i will use requests for now, until I have the time to look into what is actually going on, because creating devices, sites, etc. is no problem it is only with that specific object i have the issue.

@abhi1693 abhi1693 added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Aug 28, 2023
@abhi1693
Copy link
Member

@mickmortensen Is this still an issue?

@jeremystretch jeremystretch added the pynetbox label Nov 1, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pynetbox status: under review Further discussion is needed to determine this issue's scope and/or implementation
Projects
None yet
Development

No branches or pull requests

4 participants