-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Adding a more explicit error message when a view does have a get_queryset method but it returned nothing #5348
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
Conversation
…yset method but it returned nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fbidu Thanks for this. Welcome on board! 🙂
I just think a better error message would be helpful. If we give the class then it's an easier find.
rest_framework/permissions.py
Outdated
@@ -122,6 +122,9 @@ def has_permission(self, request, view): | |||
|
|||
if hasattr(view, 'get_queryset'): | |||
queryset = view.get_queryset() | |||
assert queryset is not None, ( | |||
'The `.get_queryset()` method from the view did not return anything.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we give a more informative message here?
Perhaps:
'Return of {}.get_queryset() was None'.format(view.__class__.__name__)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Yeah, I agree on that. Changing the message now
…ude the class name that was called
@carltongibson done 😃 |
@fbidu Thanks. |
@rpkilby Do we need a test on this? The original issue came down to the complaint that the assertion 4 lines below the change here is misleading when I'm half-inclined to say the extra assert is enough. (But I need a 2nd Opinion 🙂) |
I'm always in favor of adding tests, but this seems like an exception. The assertion is only raised under very obvious circumstances. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@fbidu Awesome work, thank you. And once again, welcome aboard! 💃🏼 |
That's sweet from you! |
@carltongibson @Neraste @rpkilby thanks!! Happy to start helping this project that did so much for me 😃 |
Description
Hello! I have been using DRF for a while and was looking at some issues to start contributing.
I found issue #4585 and tried to solve the confusing error message when a
.get_queryset()
method exists but does not return anything.Closes #4585