Skip to content

HyperlinkedRelatedField function suppresses useful context from the NoResolverMatch #3490

@mjtamlyn

Description

@mjtamlyn

NoResolverMatch recently-ish added even more helpful context about the failed resolution - paths tried, exact args/kwargs etc. DRF's HyperlinkedRelatedField replaces it with a generic message that maybe I forgot to hook up a given URL.

DRF:

Could not resolve URL for hyperlinked relationship using view name "foo".
You may have failed to include the related model in your API, or incorrectly
configured the `bar` attribute on this field.

Original exception:

Reverse for 'foo' with arguments '(u'id', 'slug')' and keyword arguments '{}' not found.
1 pattern(s) tried: [u'r/foos/(?P<id>\\d+).(?P<slug>[0-9a-f]+)/$']

In this case the fix was:

reverse('foo', kwargs, request=request)
reverse('foo', kwargs=kwargs, request=request)

Pretty clear from the original exception. If you think that the content in the DRF is useful perhaps concatenate the two, otherwise I think the original exception should be allowed to raise.

I would propose that the entire try/except block at https://github.com/tomchristie/django-rest-framework/blob/68312cb0bc6116eaf4aed18e7ffa01954e888a1f/rest_framework/relations.py#L336-L352 is removed. In particular the second half is redundant with the new Django extensions to the message.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy