Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Could not resolve URL for hyperlinked relationship using view name" error message #3291

Closed
graup opened this issue Aug 18, 2015 · 11 comments
Closed
Labels

Comments

@graup
Copy link

graup commented Aug 18, 2015

I just spent an hour trying to hunt this down. I tried to have different Serializers depending on the action. The list should only list URLs to the detail view and the detail view have all the info. I always got this error:

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

I tried everything, from manually defining the HyperlinkedIdentityField to fiddling with the viewsets... At some point I had the idea to try including the namespace when passing view_name but couldn't get it to work still.
In the end I solved this with simply removing the namespace attribute from my URL patterns.

So, my suggestion is to add this as a possible solution to the error message. It might save humanity many hours of troubleshooting.

@tomchristie
Copy link
Member

Okay, let's re-review the error message there.

@onekiloparsec
Copy link

+1 I just left a message in another issue thread but I definitely agree. The hours spent on this problem myself are dozen, and I still don' get it right.

@onekiloparsec
Copy link

None of my URLs use 'pk' but always some special identifiers such as '/api/(?P\d+)/$', or 'name' or whatever. And I couldn't disentangle this with lookup_field (and where? Meta? dedicated serializer?) and lookup_url_args?
BTW, removing the namespace attribute from my URLs pattern had no effect for me.

@onekiloparsec
Copy link

My bad, it was a typo in my URL view name. I managed to fix my bug.
Nonetheless, could this error message be improved by displaying the lookup_field (and not only the view name)? Could it be possible to detect whether the view-name exists or not?

@onekiloparsec
Copy link

Last comment: the error message suggests that the reason why an error occurs is related to the model, or the lookup_field, while these two are certainly the first things to implement (and the first things to get right). What lead me in wrong directions is that other reasons could be the source of this error, not related to the model or the lookup_field.

@tomchristie
Copy link
Member

100% agree that it is a horrible error message to have to show to users.
Difficult because the URL configuration is completely separate to the serializer configuration, but both need to match up. Not obv exactly what we should do, but would be nice if could print a contextually helpful error message...

  1. Is there a view with this name, but different arguments?
  2. Is there a view with this base name but under a different namespace?
  3. No view with this name at all.

Furthermore, command-line options to print URL configurations / serializers might also be helpful?

@onekiloparsec
Copy link

It looks like excellent ideas. I'll have a look a bit more on the DRF code to try suggesting solutions, as soon as I can grab some time.

@tomchristie
Copy link
Member

Closing this off given that Closing this off given #3816 improves the namespacing issue.

No doubt there's plenty of usability improvements we could make around handling hyperlinked URLs, but we can tackle them as specific issues if anyone has any specific improvements in mind.

@zxwild
Copy link

zxwild commented Aug 4, 2017

Just spent about 2 hours to find what it was.
Is this error message something like a "you are not ready" filter for newbies?

@xordoquy
Copy link
Collaborator

xordoquy commented Aug 4, 2017

This is a message meaning that it couldn't be resolved. There are plenty reasons why this could fail and I don't think a way we can help more here.

@zhenda-hub
Copy link

delete namespace helped me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants