Skip to content

Commit

Permalink
Resolved issue #36
Browse files Browse the repository at this point in the history
  • Loading branch information
apragacz committed Feb 25, 2019
1 parent 4d56442 commit 57cce67
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion rest_registration/utils/users.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
from django.contrib import auth
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.http import Http404
from rest_framework.generics import get_object_or_404
from django.shortcuts import get_object_or_404 as _get_object_or_404

from rest_registration.exceptions import UserNotFound
from rest_registration.settings import registration_settings

_RAISE_EXCEPTION = object()


def get_object_or_404(queryset, *filter_args, **filter_kwargs):
"""
Same as Django's standard shortcut, but make sure to also raise 404
if the filter_kwargs don't match the required types.
This function was copied from rest_framework.generics because of issue #36.
"""
try:
return _get_object_or_404(queryset, *filter_args, **filter_kwargs)
except (TypeError, ValueError, ValidationError):
raise Http404


def get_user_setting(name):
setting_name = 'USER_{name}'.format(name=name)
user_class = get_user_model()
Expand Down

1 comment on commit 57cce67

@carltongibson
Copy link

Choose a reason for hiding this comment

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

These changes shouldn't be necessary. Better to fix Simple JWT as per encode/django-rest-framework#6478 (comment)

Please sign in to comment.