Skip to content

Commit

Permalink
Fix private view ser when it is a relation in public views
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Jan 29, 2024
1 parent 65fa89f commit 34e6772
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api/base/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,16 @@ def get_url(self, obj, view_name, request, format):
view = self._handle_callable_view(obj, view)
if request.parser_context['kwargs'].get('version', False):
kwargs.update({'version': request.parser_context['kwargs']['version']})
url = drf_reverse(view, kwargs=kwargs, request=request, format=format)
try:
url = drf_reverse(view, kwargs=kwargs, request=request, format=format)
except NoReverseMatch as e:
# Handle private endpoint view serialization when it is a relationship in a public one
if kwargs.get('version', False):
kwargs.pop('version')
url = utils.absolute_reverse(view, kwargs=kwargs)
else:
raise e

if self.filter:
formatted_filters = self.format_filter(obj)
if formatted_filters:
Expand Down

0 comments on commit 34e6772

Please sign in to comment.