jazzband / django-oauth-toolkit

OAuth2 goodies for the Djangonauts!
https://django-oauth-toolkit.readthedocs.io
Other
3.06k stars 777 forks source link

ModuleNotFoundError: No module named 'oauth2_providerapi' #1407

Closed Alwinator closed 3 months ago

Alwinator commented 3 months ago

Describe the bug I am currently migrating a large enterprise django application to OAuth2.0 with PKCE.

To Reproduce Due to the confidentially agreement I cannot provide the source code, but I can test any recommendations from you.

  1. I followed this documentation: django-oauth-toolkit installation
  2. At the last step when I run migrate the application crashes with the following stack trace (Same error with makemigrations and runserver):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/MyUser/Programming/my-project/manage.py", line 21, in main
    execute_from_command_line(sys.argv)
  File "/Users/MyUser/Programming/my-project/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/Users/MyUser/Programming/my-project/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 416, in execute
    django.setup()
  File "/Users/MyUser/Programming/my-project/.venv/lib/python3.12/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/MyUser/Programming/my-project/.venv/lib/python3.12/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/MyUser/Programming/my-project/.venv/lib/python3.12/site-packages/django/apps/config.py", line 193, in create
    import_module(entry)
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'oauth2_providerapi'

I am using the following package versions:

python = ">=3.10,<3.13"
django = ">=5.0.3"
django-admin-list-filter-dropdown = ">=1.0.3"
django-admin-rangefilter = ">=0.12.1"
django-extensions = ">=3.2.3"
django-filter = ">=23.5"
django-import-export = ">=3.3.7"
django-tables2 = ">=2.7.0"
djangorestframework-camel-case = ">=1.4.2"
djangorestframework-xml = ">=2.0.0"
djangorestframework = ">=3.14.0"
drf-yasg = ">=1.21.7"
drf-nested-routers = ">=0.93.5"
pytz = ">=2024.1"
six = ">=1.16.0"
sqlparse = ">=0.4.4"
markupsafe = ">=2.1.5"
markdown = ">=3.5.2"
mysqlclient = ">=2.2.4"
pyyaml = ">=6.0.1"
jinja2 = ">=3.1.3"
gunicorn = ">=21.2.0"
whitenoise = ">=6.6.0"
humanfriendly = ">=10.0"
ldap3 = ">=2.9.1"
requests-ntlm = ">=1.2.0"
openid-connect = ">=0.5.0"
django-guardian = ">=2.4.0"
django-cors-headers = ">=4.3.1"
envparse = ">=0.2.0"
python-jwt = ">=4.1.0"
backoff = "1.8.0"
django-mysql = ">=4.12.0"
webexteamssdk = ">=1.6.1"
pyodbc = ">=5.1.0"
bitmath = ">=1.3.3.1"
premailer = ">=3.10.0"
mssql-django = ">=1.4"
pandas = ">=2.2.1"
django-oauth-toolkit = "^2.3.0"
# [...] company internal packages

I also tried with Python 3.9 and django 3.2 and got the same issue.

Expected behavior Application should migrate, start, ... (not crash)

Version 2.3.0

Additional context I am developing on a MacBook Pro M3 (Apple Silicon, ARM)

Alwinator commented 3 months ago

Fixed by changing the order in the Django INSTALLED_APPS. I have put the oauth2_provider first after the django apps, but before all other 3rd party apps, and now it works fine.