-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
Checklist
- I have verified that that issue exists against the
master
branch of Django REST framework. - I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- This is not a usage question. (Those should be directed to the discussion group instead.)
- This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- I have reduced the issue to the simplest possible case.
- I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Also refer to: #5187
Steps to reproduce
# create a basic ViewSet
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register(r'my-viewset', MyViewSet, base_name='my-viewset')
Send a GET
, PUT
, or PATCH
to a detail view, deliberately mangling the primary key:
/my-viewset/foobar/
Expected behavior
HTTP400
Actual behavior
HTTP500 unhandled exception. Traceback:
Internal Server Error: /my-viewset/foobar/
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/rest_framework/viewsets.py", line 90, in view
return self.dispatch(request, *args, **kwargs)
File "/code/siop/views/API/forecast.py", line 263, in dispatch
return super(ForecastConfigViewSet, self).dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 489, in dispatch
response = self.handle_exception(exc)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 449, in handle_exception
self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 486, in dispatch
response = handler(request, *args, **kwargs)
File "/code/siop/views/API/forecast.py", line 293, in retrieve
instance = self.get_object(pk=pk)
File "/code/siop/views/API/forecast.py", line 275, in get_object
return ForecastConfig.objects.filter(fk_client=self.client, fk_user=self.user, pk=pk).first()
File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 784, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 802, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1250, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1276, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1210, in build_filter
condition = self.build_lookup(lookups, col, value)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1104, in build_lookup
return final_lookup(lhs, rhs)
File "/usr/local/lib/python3.6/site-packages/django/db/models/lookups.py", line 24, in init
self.rhs = self.get_prep_lookup()
File "/usr/local/lib/python3.6/site-packages/django/db/models/lookups.py", line 74, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)
File "/usr/local/lib/python3.6/site-packages/django/db/models/fields/init.py", line 966, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'foobar'