From e00a5daccf156885bbde434c297bf027f9b403f8 Mon Sep 17 00:00:00 2001 From: Anders Steinlein Date: Sat, 6 Feb 2016 22:21:39 +0100 Subject: [PATCH] Fix potential circular import edge-case Fixes #158 --- rest_framework_json_api/exceptions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rest_framework_json_api/exceptions.py b/rest_framework_json_api/exceptions.py index 1e976dfe..935fecdb 100644 --- a/rest_framework_json_api/exceptions.py +++ b/rest_framework_json_api/exceptions.py @@ -2,12 +2,18 @@ from django.utils import six, encoding from django.utils.translation import ugettext_lazy as _ from rest_framework import status, exceptions -from rest_framework.views import exception_handler as drf_exception_handler from rest_framework_json_api.utils import format_value def exception_handler(exc, context): + # Import this here to avoid potential edge-case circular imports, which + # crashes with: + # "ImportError: Could not import 'rest_framework_json_api.parsers.JSONParser' for API setting + # 'DEFAULT_PARSER_CLASSES'. ImportError: cannot import name 'exceptions'.'" + # + # Also see: https://github.com/django-json-api/django-rest-framework-json-api/issues/158 + from rest_framework.views import exception_handler as drf_exception_handler response = drf_exception_handler(exc, context) if not response: