API Insert new virtual machine fail #2029

Closed
opened 2025-12-29 17:21:36 +01:00 by adam · 3 comments
Owner

Originally created by @CoinK0in on GitHub (Sep 27, 2018).

Environment:

  • Python version: 3.5.3
  • NetBox version: 2.4.4
  • Postgresql version: 9.6

Steps to Reproduce

POST request on API URL api/virtualization/virtual-machines/ with data like :

{"name":"antispam.example.com","site":{"id":3,"slug":"datacenter-3","name":"Datacenter 3"},"cluster":{"id":6,"name":"esx16"},"vcpus":4,"role":{"slug":"antispam_v7","id":15,"name":"antispam_v7"},"memory":24576,"disk":150,"tenant":{"slug":"example","id":1,"name":"Example"}}

Expected Behavior

Creating a new virtual machine.

Observed Behavior

Return code API 500, with following error :

django.db.utils.IntegrityError
null value in column "cluster_id" violates not-null constraint
DETAIL:  Failing row contains (824, 2018-09-27, 2018-09-27 08:43:14.971329+00, antispam.example.com, 4, 24576, 150, , null, null, null, null, null, 1, null).

The query in postgresql look like :

INSERT INTO "virtualization_virtualmachine" ("created", "last_updated", "cluster_id", "tenant_id", "platform_id", "name", "status", "role_id", "primary_ip4_id", "primary_ip6_id", "vcpus", "memory", "disk", "comments") VALUES ('2018-09-27'::date, '2018-09-27T08:43:14.971329+00:00'::timestamptz, NULL, NULL, NULL, 'antispam.example.com', 1, NULL, NULL, NULL, 4, 24576, 150, '') RETURNING "virtualization_virtualmachine"."id"

Others informations

I tried to do the queries in several different formats.
Without json in the subfields, only with the IDs (Like a version 2.2.4).
Without specifying the ID, only with name / slug.
I always have the same result, when I do not have an error related to a syntax problem.

When I create a virtual machine from the interface, the postgresql query is correct and looks like:

 INSERT INTO "virtualization_virtualmachine" ("created", "last_updated", "cluster_id", "tenant_id", "platform_id", "name", "status", "role_id", "primary_ip4_id", "primary_ip6_id", "vcpus", "memory", "disk", "comments") VALUES ('2018-09-27'::date, '2018-09-27T08:54:33.867003+00:00'::timestamptz, 6, 1, NULL, 'test', 1, 15, NULL, NULL, 4, 25576, 150, '') RETURNING "virtualization_virtualmachine"."id"
Originally created by @CoinK0in on GitHub (Sep 27, 2018). ### Environment: * Python version: 3.5.3 * NetBox version: 2.4.4 * Postgresql version: 9.6 ### Steps to Reproduce **POST** request on API URL `api/virtualization/virtual-machines/` with data like : ```JSON {"name":"antispam.example.com","site":{"id":3,"slug":"datacenter-3","name":"Datacenter 3"},"cluster":{"id":6,"name":"esx16"},"vcpus":4,"role":{"slug":"antispam_v7","id":15,"name":"antispam_v7"},"memory":24576,"disk":150,"tenant":{"slug":"example","id":1,"name":"Example"}} ``` ### Expected Behavior Creating a new virtual machine. ### Observed Behavior Return code API 500, with following error : ```sql django.db.utils.IntegrityError null value in column "cluster_id" violates not-null constraint DETAIL: Failing row contains (824, 2018-09-27, 2018-09-27 08:43:14.971329+00, antispam.example.com, 4, 24576, 150, , null, null, null, null, null, 1, null). ``` The query in postgresql look like : ```sql INSERT INTO "virtualization_virtualmachine" ("created", "last_updated", "cluster_id", "tenant_id", "platform_id", "name", "status", "role_id", "primary_ip4_id", "primary_ip6_id", "vcpus", "memory", "disk", "comments") VALUES ('2018-09-27'::date, '2018-09-27T08:43:14.971329+00:00'::timestamptz, NULL, NULL, NULL, 'antispam.example.com', 1, NULL, NULL, NULL, 4, 24576, 150, '') RETURNING "virtualization_virtualmachine"."id" ``` ### Others informations I tried to do the queries in several different formats. Without json in the subfields, only with the IDs (Like a version 2.2.4). Without specifying the ID, only with name / slug. I always have the same result, when I do not have an error related to a syntax problem. When I create a virtual machine from the interface, the postgresql query is correct and looks like: ```sql INSERT INTO "virtualization_virtualmachine" ("created", "last_updated", "cluster_id", "tenant_id", "platform_id", "name", "status", "role_id", "primary_ip4_id", "primary_ip6_id", "vcpus", "memory", "disk", "comments") VALUES ('2018-09-27'::date, '2018-09-27T08:54:33.867003+00:00'::timestamptz, 6, 1, NULL, 'test', 1, 15, NULL, NULL, 4, 25576, 150, '') RETURNING "virtualization_virtualmachine"."id" ```
adam closed this issue 2025-12-29 17:21:36 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 27, 2018):

{"name":"antispam.example.com","site":{"id":3,"slug":"datacenter-3","name":"Datacenter 3"},"cluster":{"id":6,"name":"esx16"},"vcpus":4,"role":{"slug":"antispam_v7","id":15,"name":"antispam_v7"},"memory":24576,"disk":150,"tenant":{"slug":"example","id":1,"name":"Example"}}

This is not a valid API request. Related objects such as site must be specified by their integer primary key (e.g. 123), not a JSON object. Please see the API documentation for reference.

@jeremystretch commented on GitHub (Sep 27, 2018): ``` {"name":"antispam.example.com","site":{"id":3,"slug":"datacenter-3","name":"Datacenter 3"},"cluster":{"id":6,"name":"esx16"},"vcpus":4,"role":{"slug":"antispam_v7","id":15,"name":"antispam_v7"},"memory":24576,"disk":150,"tenant":{"slug":"example","id":1,"name":"Example"}} ``` This is not a valid API request. Related objects such as site must be specified by their integer primary key (e.g. `123`), not a JSON object. Please see [the API documentation](https://netbox.readthedocs.io/en/stable/api/overview/) for reference.
Author
Owner

@mkaina2 commented on GitHub (Mar 19, 2019):

Hi!
seems a bit confusing !
in swagger docs ids are not required
image

@mkaina2 commented on GitHub (Mar 19, 2019): Hi! seems a bit confusing ! in swagger docs ids are not required ![image](https://user-images.githubusercontent.com/2117476/54617727-2042a600-4a62-11e9-9912-b43ca96f372a.png)
Author
Owner

@DanSheps commented on GitHub (Mar 19, 2019):

Hi!
seems a bit confusing !
in swagger docs ids are not required

Please open a new issue for this.

Make sure you conform to one of the provided templates as required by the contributing guide.

@DanSheps commented on GitHub (Mar 19, 2019): > Hi! > seems a bit confusing ! > in swagger docs ids are not required Please open a new issue for this. Make sure you conform to one of the [provided templates](https://github.com/digitalocean/netbox/issues/new/choose) as required by the [contributing guide](https://github.com/digitalocean/netbox/blob/master/CONTRIBUTING.md).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2029