Dependency between two objects (module-bay and module) in API - creation of one or the other impossible #8534

Closed
opened 2025-12-29 20:37:51 +01:00 by adam · 4 comments
Owner

Originally created by @Etibru on GitHub (Aug 30, 2023).

NetBox version

v3.5.9

Python version

3.10

Steps to Reproduce

  1. juste form the swager UI we can see the problem.

POST [/api/dcim/module-bays/] :

field required:

  • device (int)
  • name (str)
  • installed_module (int)

POST [/api/dcim/module/] :

field required:

  • device (int)
  • module_bay (int)
  • module_type (int)

So if i want to add a new module-bays to a device, i need to create a module, but if want to create a module i need a module-bays....

Form the UI, the behavior is not the same, if you want to add a new module-bays to a device, you need to create the module-bays without module, it's after created that you can connect a module.

Expected Behavior

Same behavior as in the UI, so create module-bays with the field installed_module not required.

Observed Behavior

I cannot create (from the API), a module-bay without module and
"field is requierd"

Originally created by @Etibru on GitHub (Aug 30, 2023). ### NetBox version v3.5.9 ### Python version 3.10 ### Steps to Reproduce 1. juste form the swager UI we can see the problem. # POST [/api/dcim/module-bays/] : ## field required: - device (int) - name (str) - **installed_module (int)** # POST [/api/dcim/module/] : ## field required: - device (int) - **module_bay (int)** - module_type (int) So if i want to add a new module-bays to a device, i need to create a module, but if want to create a module i need a module-bays.... Form the UI, the behavior is not the same, if you want to add a new module-bays to a device, you need to create the module-bays without module, it's after created that you can connect a module. ### Expected Behavior Same behavior as in the UI, so create module-bays with the field **installed_module** not required. ### Observed Behavior I cannot create (from the API), a module-bay without module and "field is requierd"
adam closed this issue 2025-12-29 20:37:51 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 30, 2023):

I cannot create (from the API), a module-bay without module and "field is requierd"

Have you actually tried this? installed_module is not a required field.

$ curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/dcim/module-bays/ \
--data '{"device": 96, "name": "Bay 1"}'
{
    "id": 29,
    "url": "http://netbox:8000/api/dcim/module-bays/29/",
    "display": "Bay 1",
    "device": {
        "id": 96,
        "url": "http://netbox:8000/api/dcim/devices/96/",
        "display": "ncsu-coreswitch1",
        "name": "ncsu-coreswitch1"
    },
    "name": "Bay 1",
    "installed_module": null,
    "label": "",
    "position": "",
    "description": "",
    "tags": [],
    "custom_fields": {},
    "created": "2023-08-30T12:12:21.861781Z",
    "last_updated": "2023-08-30T12:12:21.861789Z"
}
@jeremystretch commented on GitHub (Aug 30, 2023): > I cannot create (from the API), a module-bay without module and "field is requierd" Have you actually tried this? `installed_module` is _not_ a required field. ``` $ curl -X POST \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://netbox:8000/api/dcim/module-bays/ \ --data '{"device": 96, "name": "Bay 1"}' { "id": 29, "url": "http://netbox:8000/api/dcim/module-bays/29/", "display": "Bay 1", "device": { "id": 96, "url": "http://netbox:8000/api/dcim/devices/96/", "display": "ncsu-coreswitch1", "name": "ncsu-coreswitch1" }, "name": "Bay 1", "installed_module": null, "label": "", "position": "", "description": "", "tags": [], "custom_fields": {}, "created": "2023-08-30T12:12:21.861781Z", "last_updated": "2023-08-30T12:12:21.861789Z" } ```
Author
Owner

@Etibru commented on GitHub (Aug 30, 2023):

curl -X 'POST' \
  'http://X.X.X.X:8100/api/dcim/module-bays/' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'X-CSRFTOKEN: xf44QHcxfyCFVIUuE3MbyRrGixhmeSlyyTdQpyVYfLVr3HrX0tocntF5Z7XNlXam' \
  -d '{
  "device": 176,
  "name": "mod01",
  "installed_module": null,
  "position": "1",
  "description": "test"
}'

You're right, it works with null, I missed testing this case :(
But perhaps it would be better to specify this in the swagger, as it's not marked as nullable
image

@Etibru commented on GitHub (Aug 30, 2023): ```bash curl -X 'POST' \ 'http://X.X.X.X:8100/api/dcim/module-bays/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'X-CSRFTOKEN: xf44QHcxfyCFVIUuE3MbyRrGixhmeSlyyTdQpyVYfLVr3HrX0tocntF5Z7XNlXam' \ -d '{ "device": 176, "name": "mod01", "installed_module": null, "position": "1", "description": "test" }' ``` You're right, it works with null, I missed testing this case :( But perhaps it would be better to specify this in the swagger, as it's not marked as nullable ![image](https://github.com/netbox-community/netbox/assets/56799322/9b2c8584-dd20-49b5-a4f2-d46cf61104e0)
Author
Owner

@jeremystretch commented on GitHub (Aug 30, 2023):

You're right, it works with null, I missed testing this case :(

It doesn't sound like you tested it at all prior to submitting this bug report.

But perhaps it would be better to specify this in the swagger, as it's not marked as nullable

You're welcome to submit a new issue proposing this change. I'm going to close this one out as invalid, as the described functionality does in fact work.

@jeremystretch commented on GitHub (Aug 30, 2023): > You're right, it works with null, I missed testing this case :( It doesn't sound like you tested it _at all_ prior to submitting this bug report. > But perhaps it would be better to specify this in the swagger, as it's not marked as nullable You're welcome to submit a new issue proposing this change. I'm going to close this one out as invalid, as the described functionality does in fact work.
Author
Owner

@Etibru commented on GitHub (Aug 30, 2023):

I didn't test with null, because the swagger didn't have the indication "nullable: true" and the field is with "*", I should have been more curious and tested with null

Some fields in the swagger are like this:
image

@Etibru commented on GitHub (Aug 30, 2023): I didn't test with null, because the swagger didn't have the indication "_nullable: true_" and the field is with "*", I should have been more curious and tested with null Some fields in the swagger are like this: ![image](https://github.com/netbox-community/netbox/assets/56799322/afbdc115-970c-45fe-8635-1ff7309d00b9)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8534