Skip to content

Add ValidationError to except in get_object_or_404 for django 1.11 #5126

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

Merged
merged 1 commit into from
May 11, 2017

Conversation

njamaleddine
Copy link
Contributor

@njamaleddine njamaleddine commented May 6, 2017

Description

Add ValidationError to except in rest_framework.generics.get_object_or_404 to handle change in Django 1.11 where get_object_or_404 returns a ValidationError (as opposed to earlier versions that returned a ValueError) when passing an invalid value for the uuid.

Refs #3377 (I'd be happy to open up a separate issue for this as well, but wasn't sure if I should)

@xordoquy xordoquy merged commit a251b93 into encode:master May 11, 2017
@xordoquy xordoquy added this to the 3.6.3 Release milestone May 11, 2017
@xordoquy
Copy link
Collaborator

Thank you for the fix.

@@ -18,7 +19,7 @@ def get_object_or_404(queryset, *filter_args, **filter_kwargs):
"""
try:
return _get_object_or_404(queryset, *filter_args, **filter_kwargs)
except (TypeError, ValueError):
except (TypeError, ValueError, ValidationError):

Choose a reason for hiding this comment

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

Shouldn't it re-raise it as a DRF validation error?

Copy link
Member

Choose a reason for hiding this comment

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

The method is get_object_or_404, the raise Http404 here is to keep it consistent with the get_object_or_404 method that is implemented within the Django core.

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

Successfully merging this pull request may close these issues.

4 participants