Unable to reference object id in site using REST API #9612

Closed
opened 2025-12-29 21:19:43 +01:00 by adam · 2 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. Create a tenant named "Test Tenant". Make a note of the tenant's id (in my case it's 7)
  2. Create a site using REST API
curl -s -X POST \
-H "Authorization: Token 0123456789abcdef0123456789abcdef01234567" \
-H "Content-Type: application/json" \
http://localhost:32768/api/dcim/sites/ \
--data '{"name": "Test site 1", "slug": "test-site-1", "tenant": 7}' | jq '.'

Expected Behavior

The site is created in and tenant is set to Test tenant.

Observed Behavior

{
  "tenant": {
    "non_field_errors": [
      "Invalid data. Expected a dictionary, but got int."
    ]
  }
}

The same API calls work as expected in NetBox 3.7.

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. Create a tenant named "Test Tenant". Make a note of the tenant's id (in my case it's 7) 2. Create a site using REST API ``` curl -s -X POST \ -H "Authorization: Token 0123456789abcdef0123456789abcdef01234567" \ -H "Content-Type: application/json" \ http://localhost:32768/api/dcim/sites/ \ --data '{"name": "Test site 1", "slug": "test-site-1", "tenant": 7}' | jq '.' ``` ### Expected Behavior The site is created in and tenant is set to Test tenant. ### Observed Behavior ``` { "tenant": { "non_field_errors": [ "Invalid data. Expected a dictionary, but got int." ] } } ``` The same API calls work as expected in NetBox 3.7.
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 21:19:43 +01:00
adam closed this issue 2025-12-29 21:19:43 +01:00
Author
Owner

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

I see the issue with SiteSerializer; we're not passing nested=True to TenantSerializer. Easy fix.

@rodvand have you come across this issue for any other models? A quick check suggests it affects only the site model, but I'll do a more thorough audit.

@jeremystretch commented on GitHub (May 7, 2024): I see the issue with SiteSerializer; we're not passing `nested=True` to TenantSerializer. Easy fix. @rodvand have you come across this issue for any other models? A quick check suggests it affects only the site model, but I'll do a more thorough audit.
Author
Owner

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

@rodvand have you come across this issue for any other models? A quick check suggests it affects only the site model, but I'll do a more thorough audit.

I'll update if I come by any more of this issue.

@rodvand commented on GitHub (May 7, 2024): > @rodvand have you come across this issue for any other models? A quick check suggests it affects only the site model, but I'll do a more thorough audit. I'll update if I come by any more of this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9612