From a6b03b88847f2ce1951b4a7b3bfd2c499271867e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 29 Jun 2020 10:38:32 -0400 Subject: [PATCH] Update WritableNestedSerializer to call unrestricted() on RestrictedQuerySets --- netbox/utilities/api.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/netbox/utilities/api.py b/netbox/utilities/api.py index 2e2d7f7f5..067af9e5a 100644 --- a/netbox/utilities/api.py +++ b/netbox/utilities/api.py @@ -254,8 +254,11 @@ class WritableNestedSerializer(ModelSerializer): # Dictionary of related object attributes if isinstance(data, dict): params = dict_to_filter_params(data) + queryset = self.Meta.model.objects + if hasattr(queryset, 'restrict'): + queryset = queryset.unrestricted() try: - return self.Meta.model.objects.get(**params) + return queryset.get(**params) except ObjectDoesNotExist: raise ValidationError( "Related object not found using the provided attributes: {}".format(params) @@ -281,8 +284,11 @@ class WritableNestedSerializer(ModelSerializer): ) # Look up object by PK + queryset = self.Meta.model.objects + if hasattr(queryset, 'restrict'): + queryset = queryset.unrestricted() try: - return self.Meta.model.objects.get(pk=int(data)) + return queryset.get(pk=int(data)) except ObjectDoesNotExist: raise ValidationError( "Related object not found using the provided numeric ID: {}".format(pk)