Skip to content
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

Compatibility with simplejwt #36

Closed
anton-shestakov opened this issue Feb 24, 2019 · 3 comments
Closed

Compatibility with simplejwt #36

anton-shestakov opened this issue Feb 24, 2019 · 3 comments
Assignees
Labels

Comments

@anton-shestakov
Copy link

Hi @apragacz

First of all, thanks for your work on this nice package. It has minimum set of features and it's just exactly what I need for one of the projects I'm working on.

Now, back to the issue, this package is not compatible with django-rest-framework-simplejwt package which is recommended by django-rest-framework official docs as implementation of JWT authentication.

Problem may also appear with anything that uses django models and specified in rest framework settings (e.g. custom authenticating classes, custom permission classes, etc.). Issue is caused by this line in code triggering all django rest framework settings import while doing checks.

Below is full traceback that appears when I do runserver with following packages installed:

Django==2.1.7
django-rest-registration==0.3.14
djangorestframework==3.9.1
djangorestframework-simplejwt==4.0.0
pkg-resources==0.0.0
PyJWT==1.7.1
pytz==2018.9

and following django settings (others have default values)

INSTALLED_APPS = [
    'django.contrib.auth',
    'rest_registration',
    'rest_framework',
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
}
(venv) a-shestakov@ubuntu:~/Projects/test_project/jwt_test$ ./manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f372c9a7510>
Traceback (most recent call last):
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception
    raise _exception[1]
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/apps/config.py", line 116, in create
    mod = import_module(mod_path)
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_registration/apps.py", line 3, in <module>
    import rest_registration.checks  # noqa
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_registration/checks.py", line 7, in <module>
    from rest_registration.notifications.email import parse_template_config
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_registration/notifications/__init__.py", line 1, in <module>
    from .email import (  # noqa: F401
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_registration/notifications/email.py", line 10, in <module>
    from rest_registration.utils.users import get_user_setting
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_registration/utils/users.py", line 4, in <module>
    from rest_framework.generics import get_object_or_404
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_framework/generics.py", line 11, in <module>
    from rest_framework import mixins, views
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_framework/views.py", line 19, in <module>
    from rest_framework.schemas import DefaultSchema
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_framework/schemas/__init__.py", line 32, in <module>
    authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_framework/settings.py", line 227, in __getattr__
    val = perform_import(val, attr)
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_framework/settings.py", line 172, in perform_import
    return [import_from_string(item, setting_name) for item in val]
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_framework/settings.py", line 172, in <listcomp>
    return [import_from_string(item, setting_name) for item in val]
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_framework/settings.py", line 183, in import_from_string
    module = import_module(module_path)
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_framework_simplejwt/authentication.py", line 5, in <module>
    from .models import TokenUser
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/rest_framework_simplejwt/models.py", line 1, in <module>
    from django.contrib.auth import models as auth_models
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/db/models/base.py", line 87, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/apps/registry.py", line 249, in get_containing_app_config
    self.check_apps_ready()
  File "/home/a-shestakov/Projects/test_project/venv/lib/python3.6/site-packages/django/apps/registry.py", line 132, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Temporary solution for me is to exclude rest_registration from INSTALLED_APPS, include views to urlconf and provide required email templates manually. But it would be nice if this was fixed.

Thanks,
Anton

@apragacz apragacz self-assigned this Feb 25, 2019
@apragacz
Copy link
Owner

Hi @anton-shestakov,
thanks for a very detailed bug report, it was really helpful!

I was able to reproduce the bug. I think the problem lies much deeper, in the way some of the of the django-rest-framework module is implemented (also some implementation details in django-rest-framework-simplejwt don't help here).

Until the problem will be fixed in DRF I will try to fix it by limiting the imports to bare minimum. Hopefully I will have time today this evening to do this.

apragacz added a commit that referenced this issue Feb 25, 2019
@apragacz
Copy link
Owner

@anton-shestakov I released the fix in version 0.4.1. Unfortunately, it is not easily to be tested automatically, so I tested it only manually.

@lock
Copy link

lock bot commented Feb 28, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants