Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
138f0cac
Commit
138f0cac
authored
May 28, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise 404 on incorrect lookup type in URL, not 500. Closes #890.
parent
7123f0b1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletions
+22
-1
rest_framework/generics.py
+12
-1
rest_framework/tests/generics.py
+10
-0
No files found.
rest_framework/generics.py
View file @
138f0cac
...
@@ -6,7 +6,7 @@ from __future__ import unicode_literals
...
@@ -6,7 +6,7 @@ from __future__ import unicode_literals
from
django.core.exceptions
import
ImproperlyConfigured
,
PermissionDenied
from
django.core.exceptions
import
ImproperlyConfigured
,
PermissionDenied
from
django.core.paginator
import
Paginator
,
InvalidPage
from
django.core.paginator
import
Paginator
,
InvalidPage
from
django.http
import
Http404
from
django.http
import
Http404
from
django.shortcuts
import
get_object_or_404
from
django.shortcuts
import
get_object_or_404
as
_get_object_or_404
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
rest_framework
import
views
,
mixins
,
exceptions
from
rest_framework
import
views
,
mixins
,
exceptions
from
rest_framework.request
import
clone_request
from
rest_framework.request
import
clone_request
...
@@ -14,6 +14,17 @@ from rest_framework.settings import api_settings
...
@@ -14,6 +14,17 @@ from rest_framework.settings import api_settings
import
warnings
import
warnings
def
get_object_or_404
(
queryset
,
**
filter_kwargs
):
"""
Same as Django's standard shortcut, but make sure to raise 404
if the filter_kwargs don't match the required types.
"""
try
:
return
_get_object_or_404
(
queryset
,
**
filter_kwargs
)
except
(
TypeError
,
ValueError
):
raise
Http404
class
GenericAPIView
(
views
.
APIView
):
class
GenericAPIView
(
views
.
APIView
):
"""
"""
Base class for all other generic views.
Base class for all other generic views.
...
...
rest_framework/tests/generics.py
View file @
138f0cac
...
@@ -279,6 +279,16 @@ class TestInstanceView(TestCase):
...
@@ -279,6 +279,16 @@ class TestInstanceView(TestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
data
,
expected
)
self
.
assertEqual
(
response
.
data
,
expected
)
def
test_get_instance_view_incorrect_arg
(
self
):
"""
GET requests with an incorrect pk type, should raise 404, not 500.
Regression test for #890.
"""
request
=
factory
.
get
(
'/a'
)
with
self
.
assertNumQueries
(
0
):
response
=
self
.
view
(
request
,
pk
=
'a'
)
.
render
()
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
)
def
test_put_cannot_set_id
(
self
):
def
test_put_cannot_set_id
(
self
):
"""
"""
PUT requests to create a new object should not be able to set the id.
PUT requests to create a new object should not be able to set the id.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment