Skip to content

Commit

Permalink
Fixes #16011: Fix site tenant assignment by PK via REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed May 7, 2024
1 parent 4d40699 commit 9bfbca7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion netbox/dcim/api/serializers_/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SiteSerializer(NetBoxModelSerializer):
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(),
Expand Down
3 changes: 3 additions & 0 deletions netbox/dcim/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from extras.models import ConfigTemplate
from ipam.models import ASN, RIR, VLAN, VRF
from netbox.api.serializers import GenericObjectSerializer
from tenancy.models import Tenant
from utilities.testing import APITestCase, APIViewTestCases, create_test_device
from virtualization.models import Cluster, ClusterType
from wireless.choices import WirelessChannelChoices
Expand Down Expand Up @@ -152,6 +153,7 @@ def setUpTestData(cls):
Site.objects.bulk_create(sites)

rir = RIR.objects.create(name='RFC 6996', is_private=True)
tenant = Tenant.objects.create(name='Tenant 1', slug='tenant-1')

asns = [
ASN(asn=65000 + i, rir=rir) for i in range(8)
Expand All @@ -166,6 +168,7 @@ def setUpTestData(cls):
'group': groups[1].pk,
'status': SiteStatusChoices.STATUS_ACTIVE,
'asns': [asns[0].pk, asns[1].pk],
'tenant': tenant.pk,
},
{
'name': 'Site 5',
Expand Down

0 comments on commit 9bfbca7

Please sign in to comment.