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

Validate review returns the right content type #258

Merged
merged 2 commits into from
Oct 3, 2017

Conversation

moumoutte
Copy link
Contributor

@moumoutte moumoutte commented Sep 7, 2017

Review

This PR closes #257

  • Rebase from master
  • Add Changelog entry.

@moumoutte moumoutte force-pushed the 257_validate_return_json_response branch from 5197585 to 1955fe6 Compare September 7, 2017 13:41
@brunobord
Copy link
Contributor

Looking ok, although, please:

  • You must rebase your PR from master,
  • And then, you'll be able to add an entry to the Changelog.

@brunobord brunobord added this to the 1.0.1 milestone Sep 8, 2017
@brunobord
Copy link
Contributor

this branch is on hold, and will be merged targetting the 1.0.1 release

@moumoutte moumoutte force-pushed the 257_validate_return_json_response branch from 1955fe6 to 8a3c17e Compare September 8, 2017 08:48
@brunobord
Copy link
Contributor

You're clear to rebase (again, sorry), now that the 1.0.0 has been released

Copy link
Contributor

@brunobord brunobord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to add an item to the changelog, please.

@moumoutte moumoutte force-pushed the 257_validate_return_json_response branch from d156519 to cfb5d1e Compare October 3, 2017 08:38
@moumoutte
Copy link
Contributor Author

Done

@@ -242,7 +242,7 @@ def get(self, request, **kwargs):
try:
formidable = self.get_formidable_object(kwargs)
except Formidable.DoesNotExist:
raise exceptions.Http404()
raise exceptions.NotFound()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think we can only return the reference of the exception here raise exceptions.NotFound, not an instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind , just want to know why a thing is better than another :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno. I've always told that if you're not passing any argument to the exception's constructor, then there is no point of raising an instance, but a reference to the exception class suffice. It was a nitpick anyway. We can leave it as is 😉

Copy link
Contributor Author

@moumoutte moumoutte Oct 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, I think the code is actually transforming the class to an instance automatically.
In the final exception handler, we can see something like this:

https://github.com/encode/django-rest-framework/blob/master/rest_framework/views.py#L433

But, isinstance does not work on class itself.

In [3]: class C:
   ...:     pass
   ...: 

In [4]: isinstance(C(), C)
Out[4]: True

In [5]: isinstance(C, C)
Out[5]: False

So I guess, something in the code, the class is automatically instanciated.

Same thing for the default exception_handler

https://github.com/encode/django-rest-framework/blob/master/rest_framework/views.py#L58

Copy link
Contributor

@wo0dyn wo0dyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@brunobord brunobord merged commit abaa948 into master Oct 3, 2017
@brunobord brunobord deleted the 257_validate_return_json_response branch October 3, 2017 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The validation view does not return right headers
3 participants