Skip to content

Commit 57cce67

Browse files
committed
Resolved issue #36
1 parent 4d56442 commit 57cce67

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

rest_registration/utils/users.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
from django.contrib import auth
22
from django.contrib.auth import get_user_model
3+
from django.core.exceptions import ValidationError
34
from django.http import Http404
4-
from rest_framework.generics import get_object_or_404
5+
from django.shortcuts import get_object_or_404 as _get_object_or_404
56

67
from rest_registration.exceptions import UserNotFound
78
from rest_registration.settings import registration_settings
89

910
_RAISE_EXCEPTION = object()
1011

1112

13+
def get_object_or_404(queryset, *filter_args, **filter_kwargs):
14+
"""
15+
Same as Django's standard shortcut, but make sure to also raise 404
16+
if the filter_kwargs don't match the required types.
17+
18+
This function was copied from rest_framework.generics because of issue #36.
19+
"""
20+
try:
21+
return _get_object_or_404(queryset, *filter_args, **filter_kwargs)
22+
except (TypeError, ValueError, ValidationError):
23+
raise Http404
24+
25+
1226
def get_user_setting(name):
1327
setting_name = 'USER_{name}'.format(name=name)
1428
user_class = get_user_model()

0 commit comments

Comments
 (0)