Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ any parts of the framework not mentioned in the documentation should generally b
* Removed support for Django REST Framework <=3.8.
* Removed support for Django 2.0.

### Fixed

* Avoid printing invalid pointer when api returns 404


## [2.8.0] - 2019-06-13

This is the last release supporting Python 2.7, Python 3.4, Django Filter 1.1, Django REST Framework <=3.8 and Django 2.0.
Expand Down
13 changes: 13 additions & 0 deletions example/tests/test_model_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,19 @@ def test_key_in_post(self):
get_user_model().objects.get(pk=self.miles.pk).email,
'miles@trumpet.org')

def test_404_error_pointer(self):
self.client.login(username='miles', password='pw')
not_found_url = reverse('user-detail', kwargs={'pk': 12345})
errors = {
'errors': [
{'detail': 'Not found.', 'status': '404'}
]
}

response = self.client.get(not_found_url)
assert 404 == response.status_code
assert errors == response.json()


@pytest.mark.django_db
def test_patch_allow_field_type(author, author_type_factory, client):
Expand Down
7 changes: 7 additions & 0 deletions rest_framework_json_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ManyToManyDescriptor,
ReverseManyToOneDescriptor
)
from django.http import Http404
from django.utils import encoding
from django.utils.module_loading import import_string as import_class_from_dotted_path
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -405,6 +406,12 @@ def format_drf_errors(response, context, exc):
# see if they passed a dictionary to ValidationError manually
if isinstance(error, dict):
errors.append(error)
elif isinstance(exc, Http404) and isinstance(error, str):
# 404 errors don't have a pointer
errors.append({
'detail': error,
'status': encoding.force_text(response.status_code),
})
elif isinstance(error, str):
classes = inspect.getmembers(exceptions, inspect.isclass)
# DRF sets the `field` to 'detail' for its own exceptions
Expand Down