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

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

Closed
rodvand opened this issue May 7, 2024 · 8 comments · Fixed by #16008
Closed

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

rodvand opened this issue May 7, 2024 · 8 comments · Fixed by #16008
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@rodvand
Copy link
Contributor

rodvand commented May 7, 2024

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."
  ]
}
@rodvand rodvand added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels May 7, 2024
@jeremystretch
Copy link
Member

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 jeremystretch added status: under review Further discussion is needed to determine this issue's scope and/or implementation and removed status: needs triage This issue is awaiting triage by a maintainer labels May 7, 2024
@rodvand
Copy link
Contributor Author

rodvand commented 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
Copy link
Contributor Author

rodvand commented May 7, 2024

Could it maybe be fixed with something like this bfc1cab ?

@jeremystretch
Copy link
Member

jeremystretch commented 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 jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels May 7, 2024
@jeremystretch
Copy link
Member

Could it maybe be fixed with something like this bfc1cab ?

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 jeremystretch self-assigned this May 7, 2024
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels May 7, 2024
@jeremystretch
Copy link
Member

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

@jeremystretch
Copy link
Member

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
Copy link
Member

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 added a commit that referenced this issue May 7, 2024
jeremystretch added a commit that referenced this issue May 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
3 participants