Skip to content

exception on import of the serializer #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
patroqueeet opened this issue Nov 22, 2015 · 13 comments
Closed

exception on import of the serializer #158

patroqueeet opened this issue Nov 22, 2015 · 13 comments

Comments

@patroqueeet
Copy link

Dear,

my code:

from rest_framework_json_api import serializers

when using from rest_framework import serializers all is working.

the error when executing runserver and triggering a request:

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
    return self.application(environ, start_response)
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 168, in __call__
    self.load_middleware()
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 46, in load_middleware
    mw_instance = mw_class()
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/django/middleware/locale.py", line 23, in __init__
    for url_pattern in get_resolver(None).url_patterns:
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 372, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 366, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/srv/www/vbnet/site/project/urls.py", line 13, in <module>
    from location.views import VenueDetailView, VenueListView, \
  File "/srv/www/vbnet/site/location/views.py", line 19, in <module>
    from services.rest.serializers import RatingSerializer
  File "/srv/www/vbnet/site/services/rest/serializers.py", line 7, in <module>
    from rest_framework_json_api import serializers
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/rest_framework_json_api/serializers.py", line 5, in <module>
    from rest_framework_json_api.relations import ResourceRelatedField
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/rest_framework_json_api/relations.py", line 7, in <module>
    from rest_framework_json_api.exceptions import Conflict
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/rest_framework_json_api/exceptions.py", line 5, in <module>
    from rest_framework.views import exception_handler as drf_exception_handler
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/rest_framework/views.py", line 98, in <module>
    class APIView(View):
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/rest_framework/views.py", line 102, in APIView
    parser_classes = api_settings.DEFAULT_PARSER_CLASSES
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/rest_framework/settings.py", line 208, in __getattr__
    val = perform_import(val, attr)
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/rest_framework/settings.py", line 160, in perform_import
    return [import_from_string(item, setting_name) for item in val]
  File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/rest_framework/settings.py", line 176, in import_from_string
    raise ImportError(msg)
ImportError: Could not import 'rest_framework_json_api.parsers.JSONParser' for API setting 'DEFAULT_PARSER_CLASSES'. ImportError: cannot import name exceptions.

I'm running your 2.0.0.beta.2

@jerel
Copy link
Member

jerel commented Nov 22, 2015

Do your settings look roughly like this? https://github.com/django-json-api/django-rest-framework-json-api/blob/develop/example/settings/dev.py#L39-L56 The error is basic enough that I'm guessing you have something misconfigured

@patroqueeet
Copy link
Author

Dear,

settings are c&p'd:

# -- REST
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
    'PAGE_SIZE': 10,
    'PAGINATE_BY': 10,
    'PAGINATE_BY_PARAM': 'page_size',
    'MAX_PAGINATE_BY': 100,
    # DRF v3.1+
    'DEFAULT_PAGINATION_CLASS':
        'rest_framework_json_api.pagination.PageNumberPagination',
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_json_api.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser'
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_json_api.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ),
    #'DEFAULT_METADATA_CLASS': 'rest_framework_json_api.metadata.JSONAPIMetadata',
}

JSON_API_PLURALIZE_RELATION_TYPE = True
#JSON_API_FORMAT_KEYS = 'underscore'
JSON_API_FORMAT_RELATION_KEYS = 'underscore'

error smells like circular import, but I can't make sense of that.

@patroqueeet
Copy link
Author

found it:

File "/srv/www/vbnet/.ve/local/lib/python2.7/site-packages/rest_framework/views.py", line 102, in APIView
    parser_classes = api_settings.DEFAULT_PARSER_CLASSES

triggers the read of the parsers and its import. the parser class imports exceptions from . and inside exceptions we are importing:

from rest_framework.views import exception_handler as drf_exception_handler

means it requires drf.views which hence would try to get the parser class again...

@patroqueeet
Copy link
Author

I changed the imports of the parsers testwise into:

  from rest_framework import parsers, exceptions
  from rest_framework.exceptions import ParseError

  from . import utils, renderers

and its working now.

@patroqueeet
Copy link
Author

dear, I wonder why it got closed. this is a error in the package as none of my code was involved. means, adopting your code won't make sense?

can I provide anything to support you?

@asteinlein
Copy link
Contributor

I've run into this exact same issue. Why was this issue closed?

@patroqueeet
Copy link
Author

Dear, no answer since then. not sure if this package is properly maintained. feel free to see my fork. its working for me on production since december.

best

j

@jerel
Copy link
Member

jerel commented Feb 6, 2016

Yes it's maintained, I believe this issue was closed because we understood it to be resolved. If you have the fix in your fork would you be interested in opening a pull request?

@jerel jerel reopened this Feb 6, 2016
@patroqueeet
Copy link
Author

Dear, I'm hesitating as I'm already late with a pull request for django-registration as it always involves proper code, tests, docu etc. I fear I cant' deliver proper quality to contribute or it will take a long time until its done....

@asteinlein
Copy link
Contributor

I have a patch I'll push out shortly.

@asteinlein
Copy link
Contributor

I've created #201. Would really appreciate a merge so we can avoid having to use a fork. Thanks! :)

@jsenecal
Copy link
Member

jsenecal commented Feb 6, 2016

@jerel the fix is simple enough for me to merge right away. It is unfortunate that the issue is so hard to replicate, the comment should, however, prevent regression.

@asteinlein
Copy link
Contributor

Thanks!

akubetin pushed a commit to Mariana-Tek/django-rest-framework-json-api that referenced this issue Feb 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants