prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Unable to reference object id in site using REST API 
  ### 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.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `netbox/dcim/api/serializers_/sites.py`
  Content:
  ```
  1 from rest_framework import serializers
  2 from timezone_field.rest_framework import TimeZoneSerializerField
  3 
  4 from dcim.choices import *
  5 from dcim.models import Location, Region, Site, SiteGroup
  6 from ipam.api.serializers_.asns import ASNSerializer
  7 from ipam.models import ASN
  8 from netbox.api.fields import ChoiceField, RelatedObjectCountField, SerializedPKRelatedField
  9 from netbox.api.serializers import NestedGroupModelSerializer, NetBoxModelSerializer
  10 from tenancy.api.serializers_.tenants import TenantSerializer
  11 from ..nested_serializers import *
  12 
  13 __all__ = (
  14     'LocationSerializer',
  15     'RegionSerializer',
  16     'SiteGroupSerializer',
  17     'SiteSerializer',
  18 )
  19 
  20 
  21 class RegionSerializer(NestedGroupModelSerializer):
  22     url = serializers.HyperlinkedIdentityField(view_name='dcim-api:region-detail')
  23     parent = NestedRegionSerializer(required=False, allow_null=True, default=None)
  24     site_count = serializers.IntegerField(read_only=True)
  25 
  26     class Meta:
  27         model = Region
  28         fields = [
  29             'id', 'url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields', 'created',
  30             'last_updated', 'site_count', '_depth',
  31         ]
  32         brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'site_count', '_depth')
  33 
  34 
  35 class SiteGroupSerializer(NestedGroupModelSerializer):
  36     url = serializers.HyperlinkedIdentityField(view_name='dcim-api:sitegroup-detail')
  37     parent = NestedSiteGroupSerializer(required=False, allow_null=True, default=None)
  38     site_count = serializers.IntegerField(read_only=True)
  39 
  40     class Meta:
  41         model = SiteGroup
  42         fields = [
  43             'id', 'url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields', 'created',
  44             'last_updated', 'site_count', '_depth',
  45         ]
  46         brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'site_count', '_depth')
  47 
  48 
  49 class SiteSerializer(NetBoxModelSerializer):
  50     url = serializers.HyperlinkedIdentityField(view_name='dcim-api:site-detail')
  51     status = ChoiceField(choices=SiteStatusChoices, required=False)
  52     region = RegionSerializer(nested=True, required=False, allow_null=True)
  53     group = SiteGroupSerializer(nested=True, required=False, allow_null=True)
  54     tenant = TenantSerializer(required=False, allow_null=True)
  55     time_zone = TimeZoneSerializerField(required=False, allow_null=True)
  56     asns = SerializedPKRelatedField(
  57         queryset=ASN.objects.all(),
  58         serializer=ASNSerializer,
  59         nested=True,
  60         required=False,
  61         many=True
  62     )
  63 
  64     # Related object counts
  65     circuit_count = RelatedObjectCountField('circuit_terminations')
  66     device_count = RelatedObjectCountField('devices')
  67     prefix_count = RelatedObjectCountField('prefixes')
  68     rack_count = RelatedObjectCountField('racks')
  69     vlan_count = RelatedObjectCountField('vlans')
  70     virtualmachine_count = RelatedObjectCountField('virtual_machines')
  71 
  72     class Meta:
  73         model = Site
  74         fields = [
  75             'id', 'url', 'display', 'name', 'slug', 'status', 'region', 'group', 'tenant', 'facility', 'time_zone',
  76             'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'comments', 'asns', 'tags',
  77             'custom_fields', 'created', 'last_updated', 'circuit_count', 'device_count', 'prefix_count', 'rack_count',
  78             'virtualmachine_count', 'vlan_count',
  79         ]
  80         brief_fields = ('id', 'url', 'display', 'name', 'description', 'slug')
  81 
  82 
  83 class LocationSerializer(NestedGroupModelSerializer):
  84     url = serializers.HyperlinkedIdentityField(view_name='dcim-api:location-detail')
  85     site = SiteSerializer(nested=True)
  86     parent = NestedLocationSerializer(required=False, allow_null=True, default=None)
  87     status = ChoiceField(choices=LocationStatusChoices, required=False)
  88     tenant = TenantSerializer(nested=True, required=False, allow_null=True)
  89     rack_count = serializers.IntegerField(read_only=True)
  90     device_count = serializers.IntegerField(read_only=True)
  91 
  92     class Meta:
  93         model = Location
  94         fields = [
  95             'id', 'url', 'display', 'name', 'slug', 'site', 'parent', 'status', 'tenant', 'facility', 'description',
  96             'tags', 'custom_fields', 'created', 'last_updated', 'rack_count', 'device_count', '_depth',
  97         ]
  98         brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'rack_count', '_depth')
  99
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/netbox/dcim/api/serializers_/sites.py b/netbox/dcim/api/serializers_/sites.py
  --- a/netbox/dcim/api/serializers_/sites.py
  +++ b/netbox/dcim/api/serializers_/sites.py
  @@ -51,7 +51,7 @@
       status = ChoiceField(choices=SiteStatusChoices, required=False)
       region = RegionSerializer(nested=True, required=False, allow_null=True)
       group = SiteGroupSerializer(nested=True, required=False, allow_null=True)
  -    tenant = TenantSerializer(required=False, allow_null=True)
  +    tenant = TenantSerializer(nested=True, required=False, allow_null=True)
       time_zone = TimeZoneSerializerField(required=False, allow_null=True)
       asns = SerializedPKRelatedField(
           queryset=ASN.objects.all(),
  
verification_info: {"golden_diff": "diff --git a/netbox/dcim/api/serializers_/sites.py b/netbox/dcim/api/serializers_/sites.py\n--- a/netbox/dcim/api/serializers_/sites.py\n+++ b/netbox/dcim/api/serializers_/sites.py\n@@ -51,7 +51,7 @@\n     status = ChoiceField(choices=SiteStatusChoices, required=False)\n     region = RegionSerializer(nested=True, required=False, allow_null=True)\n     group = SiteGroupSerializer(nested=True, required=False, allow_null=True)\n-    tenant = TenantSerializer(required=False, allow_null=True)\n+    tenant = TenantSerializer(nested=True, required=False, allow_null=True)\n     time_zone = TimeZoneSerializerField(required=False, allow_null=True)\n     asns = SerializedPKRelatedField(\n         queryset=ASN.objects.all(),\n", "issue": "Unable to reference object id in site using REST API \n### Deployment Type\r\n\r\nSelf-hosted\r\n\r\n### NetBox Version\r\n\r\nv4.0.0\r\n\r\n### Python Version\r\n\r\n3.10\r\n\r\n### Steps to Reproduce\r\n\r\n1. Create a tenant named \"Test Tenant\". Make a note of the tenant's id (in my case it's 7)\r\n2. Create a site using REST API\r\n```\r\ncurl -s -X POST \\\r\n-H \"Authorization: Token 0123456789abcdef0123456789abcdef01234567\" \\\r\n-H \"Content-Type: application/json\" \\\r\nhttp://localhost:32768/api/dcim/sites/ \\\r\n--data '{\"name\": \"Test site 1\", \"slug\": \"test-site-1\", \"tenant\": 7}' | jq '.'\r\n```\r\n\r\n### Expected Behavior\r\n\r\nThe site is created in and tenant is set to Test tenant.\r\n\r\n### Observed Behavior\r\n\r\n```\r\n{\r\n  \"tenant\": {\r\n    \"non_field_errors\": [\r\n      \"Invalid data. Expected a dictionary, but got int.\"\r\n    ]\r\n  }\r\n}\r\n```\r\n\r\nThe same API calls work as expected in NetBox 3.7.\n", "before_files": [{"content": "from rest_framework import serializers\nfrom timezone_field.rest_framework import TimeZoneSerializerField\n\nfrom dcim.choices import *\nfrom dcim.models import Location, Region, Site, SiteGroup\nfrom ipam.api.serializers_.asns import ASNSerializer\nfrom ipam.models import ASN\nfrom netbox.api.fields import ChoiceField, RelatedObjectCountField, SerializedPKRelatedField\nfrom netbox.api.serializers import NestedGroupModelSerializer, NetBoxModelSerializer\nfrom tenancy.api.serializers_.tenants import TenantSerializer\nfrom ..nested_serializers import *\n\n__all__ = (\n    'LocationSerializer',\n    'RegionSerializer',\n    'SiteGroupSerializer',\n    'SiteSerializer',\n)\n\n\nclass RegionSerializer(NestedGroupModelSerializer):\n    url = serializers.HyperlinkedIdentityField(view_name='dcim-api:region-detail')\n    parent = NestedRegionSerializer(required=False, allow_null=True, default=None)\n    site_count = serializers.IntegerField(read_only=True)\n\n    class Meta:\n        model = Region\n        fields = [\n            'id', 'url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields', 'created',\n            'last_updated', 'site_count', '_depth',\n        ]\n        brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'site_count', '_depth')\n\n\nclass SiteGroupSerializer(NestedGroupModelSerializer):\n    url = serializers.HyperlinkedIdentityField(view_name='dcim-api:sitegroup-detail')\n    parent = NestedSiteGroupSerializer(required=False, allow_null=True, default=None)\n    site_count = serializers.IntegerField(read_only=True)\n\n    class Meta:\n        model = SiteGroup\n        fields = [\n            'id', 'url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields', 'created',\n            'last_updated', 'site_count', '_depth',\n        ]\n        brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'site_count', '_depth')\n\n\nclass SiteSerializer(NetBoxModelSerializer):\n    url = serializers.HyperlinkedIdentityField(view_name='dcim-api:site-detail')\n    status = ChoiceField(choices=SiteStatusChoices, required=False)\n    region = RegionSerializer(nested=True, required=False, allow_null=True)\n    group = SiteGroupSerializer(nested=True, required=False, allow_null=True)\n    tenant = TenantSerializer(required=False, allow_null=True)\n    time_zone = TimeZoneSerializerField(required=False, allow_null=True)\n    asns = SerializedPKRelatedField(\n        queryset=ASN.objects.all(),\n        serializer=ASNSerializer,\n        nested=True,\n        required=False,\n        many=True\n    )\n\n    # Related object counts\n    circuit_count = RelatedObjectCountField('circuit_terminations')\n    device_count = RelatedObjectCountField('devices')\n    prefix_count = RelatedObjectCountField('prefixes')\n    rack_count = RelatedObjectCountField('racks')\n    vlan_count = RelatedObjectCountField('vlans')\n    virtualmachine_count = RelatedObjectCountField('virtual_machines')\n\n    class Meta:\n        model = Site\n        fields = [\n            'id', 'url', 'display', 'name', 'slug', 'status', 'region', 'group', 'tenant', 'facility', 'time_zone',\n            'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'comments', 'asns', 'tags',\n            'custom_fields', 'created', 'last_updated', 'circuit_count', 'device_count', 'prefix_count', 'rack_count',\n            'virtualmachine_count', 'vlan_count',\n        ]\n        brief_fields = ('id', 'url', 'display', 'name', 'description', 'slug')\n\n\nclass LocationSerializer(NestedGroupModelSerializer):\n    url = serializers.HyperlinkedIdentityField(view_name='dcim-api:location-detail')\n    site = SiteSerializer(nested=True)\n    parent = NestedLocationSerializer(required=False, allow_null=True, default=None)\n    status = ChoiceField(choices=LocationStatusChoices, required=False)\n    tenant = TenantSerializer(nested=True, required=False, allow_null=True)\n    rack_count = serializers.IntegerField(read_only=True)\n    device_count = serializers.IntegerField(read_only=True)\n\n    class Meta:\n        model = Location\n        fields = [\n            'id', 'url', 'display', 'name', 'slug', 'site', 'parent', 'status', 'tenant', 'facility', 'description',\n            'tags', 'custom_fields', 'created', 'last_updated', 'rack_count', 'device_count', '_depth',\n        ]\n        brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'rack_count', '_depth')\n", "path": "netbox/dcim/api/serializers_/sites.py"}], "after_files": [{"content": "from rest_framework import serializers\nfrom timezone_field.rest_framework import TimeZoneSerializerField\n\nfrom dcim.choices import *\nfrom dcim.models import Location, Region, Site, SiteGroup\nfrom ipam.api.serializers_.asns import ASNSerializer\nfrom ipam.models import ASN\nfrom netbox.api.fields import ChoiceField, RelatedObjectCountField, SerializedPKRelatedField\nfrom netbox.api.serializers import NestedGroupModelSerializer, NetBoxModelSerializer\nfrom tenancy.api.serializers_.tenants import TenantSerializer\nfrom ..nested_serializers import *\n\n__all__ = (\n    'LocationSerializer',\n    'RegionSerializer',\n    'SiteGroupSerializer',\n    'SiteSerializer',\n)\n\n\nclass RegionSerializer(NestedGroupModelSerializer):\n    url = serializers.HyperlinkedIdentityField(view_name='dcim-api:region-detail')\n    parent = NestedRegionSerializer(required=False, allow_null=True, default=None)\n    site_count = serializers.IntegerField(read_only=True)\n\n    class Meta:\n        model = Region\n        fields = [\n            'id', 'url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields', 'created',\n            'last_updated', 'site_count', '_depth',\n        ]\n        brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'site_count', '_depth')\n\n\nclass SiteGroupSerializer(NestedGroupModelSerializer):\n    url = serializers.HyperlinkedIdentityField(view_name='dcim-api:sitegroup-detail')\n    parent = NestedSiteGroupSerializer(required=False, allow_null=True, default=None)\n    site_count = serializers.IntegerField(read_only=True)\n\n    class Meta:\n        model = SiteGroup\n        fields = [\n            'id', 'url', 'display', 'name', 'slug', 'parent', 'description', 'tags', 'custom_fields', 'created',\n            'last_updated', 'site_count', '_depth',\n        ]\n        brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'site_count', '_depth')\n\n\nclass SiteSerializer(NetBoxModelSerializer):\n    url = serializers.HyperlinkedIdentityField(view_name='dcim-api:site-detail')\n    status = ChoiceField(choices=SiteStatusChoices, required=False)\n    region = RegionSerializer(nested=True, required=False, allow_null=True)\n    group = SiteGroupSerializer(nested=True, required=False, allow_null=True)\n    tenant = TenantSerializer(nested=True, required=False, allow_null=True)\n    time_zone = TimeZoneSerializerField(required=False, allow_null=True)\n    asns = SerializedPKRelatedField(\n        queryset=ASN.objects.all(),\n        serializer=ASNSerializer,\n        nested=True,\n        required=False,\n        many=True\n    )\n\n    # Related object counts\n    circuit_count = RelatedObjectCountField('circuit_terminations')\n    device_count = RelatedObjectCountField('devices')\n    prefix_count = RelatedObjectCountField('prefixes')\n    rack_count = RelatedObjectCountField('racks')\n    vlan_count = RelatedObjectCountField('vlans')\n    virtualmachine_count = RelatedObjectCountField('virtual_machines')\n\n    class Meta:\n        model = Site\n        fields = [\n            'id', 'url', 'display', 'name', 'slug', 'status', 'region', 'group', 'tenant', 'facility', 'time_zone',\n            'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'comments', 'asns', 'tags',\n            'custom_fields', 'created', 'last_updated', 'circuit_count', 'device_count', 'prefix_count', 'rack_count',\n            'virtualmachine_count', 'vlan_count',\n        ]\n        brief_fields = ('id', 'url', 'display', 'name', 'description', 'slug')\n\n\nclass LocationSerializer(NestedGroupModelSerializer):\n    url = serializers.HyperlinkedIdentityField(view_name='dcim-api:location-detail')\n    site = SiteSerializer(nested=True)\n    parent = NestedLocationSerializer(required=False, allow_null=True, default=None)\n    status = ChoiceField(choices=LocationStatusChoices, required=False)\n    tenant = TenantSerializer(nested=True, required=False, allow_null=True)\n    rack_count = serializers.IntegerField(read_only=True)\n    device_count = serializers.IntegerField(read_only=True)\n\n    class Meta:\n        model = Location\n        fields = [\n            'id', 'url', 'display', 'name', 'slug', 'site', 'parent', 'status', 'tenant', 'facility', 'description',\n            'tags', 'custom_fields', 'created', 'last_updated', 'rack_count', 'device_count', '_depth',\n        ]\n        brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'rack_count', '_depth')\n", "path": "netbox/dcim/api/serializers_/sites.py"}]}