'group' required on create API call in tenant #9606

Closed
opened 2025-12-29 21:19:37 +01:00 by adam · 8 comments
Owner

Originally created by @rodvand on GitHub (May 7, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0.0

Python Version

3.10

Steps to Reproduce

  1. Try to create a tenant with only a name and a slug (which works through the GUI)
curl -s -X POST \
-H "Authorization: Token 0123456789abcdef0123456789abcdef01234567" \
-H "Content-Type: application/json" \
http://localhost:32768/api/tenancy/tenants/ \
--data '{"name": "Tenant 2", "slug": "tenant-2"}' | jq '.'

Expected Behavior

Tenant to be created

Observed Behavior

{
  "group": [
    "This field is required."
  ]
}
Originally created by @rodvand on GitHub (May 7, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0.0 ### Python Version 3.10 ### Steps to Reproduce 1. Try to create a tenant with only a name and a slug (which works through the GUI) ``` curl -s -X POST \ -H "Authorization: Token 0123456789abcdef0123456789abcdef01234567" \ -H "Content-Type: application/json" \ http://localhost:32768/api/tenancy/tenants/ \ --data '{"name": "Tenant 2", "slug": "tenant-2"}' | jq '.' ``` ### Expected Behavior Tenant to be created ### Observed Behavior ``` { "group": [ "This field is required." ] } ```
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 21:19:37 +01:00
adam closed this issue 2025-12-29 21:19:37 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 7, 2024):

I'm not able to reproduce this on v4.0.0:

$ curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/tenancy/tenants/ \
--data '{"name": "My Tenant 1", "slug": "my-tenant-1"}'
{
    "id": 14,
    "url": "http://netbox:8000/api/tenancy/tenants/14/",
    "display": "My Tenant 1",
    "name": "My Tenant 1",
    "slug": "my-tenant-1",
    "group": null,
    "description": "",
    "comments": "",
    "tags": [],
    "custom_fields": {
        "cust_id": null
    },
    "created": "2024-05-07T13:14:00.997561Z",
    "last_updated": "2024-05-07T13:14:00.997578Z"
}

I can't think of anything that would cause this. Do you have any custom validation rules enabled for tenants by chance?

@jeremystretch commented on GitHub (May 7, 2024): I'm not able to reproduce this on v4.0.0: ``` $ curl -X POST \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://netbox:8000/api/tenancy/tenants/ \ --data '{"name": "My Tenant 1", "slug": "my-tenant-1"}' { "id": 14, "url": "http://netbox:8000/api/tenancy/tenants/14/", "display": "My Tenant 1", "name": "My Tenant 1", "slug": "my-tenant-1", "group": null, "description": "", "comments": "", "tags": [], "custom_fields": { "cust_id": null }, "created": "2024-05-07T13:14:00.997561Z", "last_updated": "2024-05-07T13:14:00.997578Z" } ``` I can't think of anything that would cause this. Do you have any custom validation rules enabled for tenants by chance?
Author
Owner

@rodvand commented on GitHub (May 7, 2024):

This is a fresh install (netbox-docker) and I'm just trying to populate it with some data (so no validation rules). I get the same error by using the Swagger interface, as well as trying against demo.netbox.dev:

curl -X POST \
-H "Authorization: Token TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
https://demo.netbox.dev/api/tenancy/tenants/ \
--data '{"name": "My Tenant 1", "slug": "my-tenant-1"}'
{
    "group": [
        "This field is required."
    ]
}
@rodvand commented on GitHub (May 7, 2024): This is a fresh install (netbox-docker) and I'm just trying to populate it with some data (so no validation rules). I get the same error by using the Swagger interface, as well as trying against demo.netbox.dev: ``` curl -X POST \ -H "Authorization: Token TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ https://demo.netbox.dev/api/tenancy/tenants/ \ --data '{"name": "My Tenant 1", "slug": "my-tenant-1"}' { "group": [ "This field is required." ] } ```
Author
Owner

@rodvand commented on GitHub (May 7, 2024):

Could it maybe be fixed with something like this bfc1cab6df ?

@rodvand commented on GitHub (May 7, 2024): Could it maybe be fixed with something like this https://github.com/netbox-community/netbox/commit/bfc1cab6dfe620d6d0615158b4730fb5af7ede19 ?
Author
Owner

@jeremystretch commented on GitHub (May 7, 2024):

Ok, turns out I was mistakenly running and older version of DRF (from working on another bug) when I attempted to reproduce it. Sorry for the confusion.

Can confirm this is a bug. Funny that it works fine under DRF 3.14.

@jeremystretch commented on GitHub (May 7, 2024): Ok, turns out I was mistakenly running and older version of DRF (from working on another bug) when I attempted to reproduce it. Sorry for the confusion. Can confirm this is a bug. Funny that it works fine under DRF 3.14.
Author
Owner

@jeremystretch commented on GitHub (May 7, 2024):

Could it maybe be fixed with something like this bfc1cab6df ?

Adding default=None does seem to fix the issue, but we need to identify the root cause. There are plenty of similar foreign key fields defined that work as expected without explicitly declaring a null default value. I suspect it might be related to the uniqueness constraint on the Tenant model; we've run into similar problems in the past.

@jeremystretch commented on GitHub (May 7, 2024): > Could it maybe be fixed with something like this https://github.com/netbox-community/netbox/commit/bfc1cab6dfe620d6d0615158b4730fb5af7ede19 ? Adding `default=None` _does_ seem to fix the issue, but we need to identify the root cause. There are plenty of similar foreign key fields defined that work as expected without explicitly declaring a null default value. I suspect it might be related to the uniqueness constraint on the Tenant model; we've run into similar problems in the past.
Author
Owner

@jeremystretch commented on GitHub (May 7, 2024):

In case it was not obvious, a workaround for this is to include "group": null in the request when creating a new tenant.

@jeremystretch commented on GitHub (May 7, 2024): In case it was not obvious, a workaround for this is to include `"group": null` in the request when creating a new tenant.
Author
Owner

@jeremystretch commented on GitHub (May 7, 2024):

Confirmed that it's the uniqueness constraints on the Tenant model causing this. It's probably related to this change in DRF v3.15.

@jeremystretch commented on GitHub (May 7, 2024): Confirmed that it's the uniqueness constraints on the Tenant model causing this. It's probably related to [this change](https://github.com/encode/django-rest-framework/pull/7438) in DRF v3.15.
Author
Owner

@jeremystretch commented on GitHub (May 7, 2024):

I've identified the same issue affecting the following model fields:

  • CircuitTermination provider_account
  • ProviderAccount name
  • VirtualDeviceContext identifier
  • Location parent
  • Tenant group (this issue)
@jeremystretch commented on GitHub (May 7, 2024): I've identified the same issue affecting the following model fields: - CircuitTermination `provider_account` - ProviderAccount `name` - VirtualDeviceContext `identifier` - Location `parent` - Tenant `group` (this issue)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9606