Django-oauth-toolkit: Something is broken with current Django master

Created on 23 Oct 2019  路  6Comments  路  Source: jazzband/django-oauth-toolkit

Tests fail with Django master branch. It might be a problem with DRF or tests themselves, of course, needs further investigation.

======================================== test session starts ========================================
platform linux -- Python 3.8.0, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
cachedir: .tox/py38-djangomaster/.pytest_cache
Django settings: tests.settings (from environment variable)
rootdir: /home/user/src/django-oauth-toolkit, inifile: tox.ini
plugins: forked-1.1.3, django-3.6.0, cov-2.8.1, xdist-1.30.0
collected 217 items / 1 errors / 216 selected                                                       

============================================== ERRORS ===============================================
___________________________ ERROR collecting tests/test_rest_framework.py ___________________________
ImportError while importing test module '/home/user/src/django-oauth-toolkit/tests/test_rest_framework.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
.tox/py38-djangomaster/lib/python3.8/site-packages/rest_framework/settings.py:177: in import_from_string
    return import_string(val)
.tox/py38-djangomaster/lib/python3.8/site-packages/django/utils/module_loading.py:17: in import_string
    module = import_module(module_path)
.tox/py38-djangomaster/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import
    ???
<frozen importlib._bootstrap>:991: in _find_and_load
    ???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:671: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:783: in exec_module
    ???
<frozen importlib._bootstrap>:219: in _call_with_frames_removed
    ???
.tox/py38-djangomaster/lib/python3.8/site-packages/rest_framework/renderers.py:23: in <module>
    from rest_framework import VERSION, exceptions, serializers, status
.tox/py38-djangomaster/lib/python3.8/site-packages/rest_framework/serializers.py:24: in <module>
    from django.db.models.fields import FieldDoesNotExist
E   ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields' (/home/user/src/django-oauth-toolkit/.tox/py38-djangomaster/lib/python3.8/site-packages/django/db/models/fields/__init__.py)

During handling of the above exception, another exception occurred:
tests/test_rest_framework.py:12: in <module>
    from rest_framework.test import APIRequestFactory, force_authenticate
.tox/py38-djangomaster/lib/python3.8/site-packages/rest_framework/test.py:138: in <module>
    class APIRequestFactory(DjangoRequestFactory):
.tox/py38-djangomaster/lib/python3.8/site-packages/rest_framework/test.py:139: in APIRequestFactory
    renderer_classes_list = api_settings.TEST_REQUEST_RENDERER_CLASSES
.tox/py38-djangomaster/lib/python3.8/site-packages/rest_framework/settings.py:220: in __getattr__
    val = perform_import(val, attr)
.tox/py38-djangomaster/lib/python3.8/site-packages/rest_framework/settings.py:168: in perform_import
    return [import_from_string(item, setting_name) for item in val]
.tox/py38-djangomaster/lib/python3.8/site-packages/rest_framework/settings.py:168: in <listcomp>
    return [import_from_string(item, setting_name) for item in val]
.tox/py38-djangomaster/lib/python3.8/site-packages/rest_framework/settings.py:180: in import_from_string
    raise ImportError(msg)
E   ImportError: Could not import 'rest_framework.renderers.MultiPartRenderer' for API setting 'TEST_REQUEST_RENDERER_CLASSES'. ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields' (/home/user/src/django-oauth-toolkit/.tox/py38-djangomaster/lib/python3.8/site-packages/django/db/models/fields/__init__.py).


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================= 1 error in 3.38s ==========================================
ERROR: InvocationError for command /home/user/src/django-oauth-toolkit/.tox/py38-djangomaster/bin/pytest --cov=oauth2_provider --cov-report= --cov-append (exited with code 2)
______________________________________________ summary ______________________________________________
ERROR:   py38-djangomaster: commands failed

Most helpful comment

is it possibly caused by this: https://docs.djangoproject.com/en/dev/releases/3.1/?

The compatibility import of django.core.exceptions.FieldDoesNotExist in django.db.models.fields is removed.

so we'd have to update 3rd party packages by replacing:
from django.db.models.fields import FieldDoesNotExist
with
from django.core.exceptions import FieldDoesNotExist

All 6 comments

is it possibly caused by this: https://docs.djangoproject.com/en/dev/releases/3.1/?

The compatibility import of django.core.exceptions.FieldDoesNotExist in django.db.models.fields is removed.

so we'd have to update 3rd party packages by replacing:
from django.db.models.fields import FieldDoesNotExist
with
from django.core.exceptions import FieldDoesNotExist

these tests appear to be working at present. Please reopen if I am mistaken.

I've just tried upgrading to Django 3.1a this morning on a project previously using Django 3.0.6 and I'm getting this error wrt the autoslug package:

Traceback (most recent call last):
  File "./manage.py", line 21, in <module>
    main()
  File "./manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/niko/work/akei/access4all/erp/models.py", line 4, in <module>
    from autoslug import AutoSlugField
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/autoslug/__init__.py", line 12, in <module>
    from autoslug.fields import AutoSlugField
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/autoslug/fields.py", line 30, in <module>
    from autoslug.settings import slugify, autoslug_modeltranslation_enable
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/autoslug/settings.py", line 71, in <module>
    slugify = get_callable(slugify_function_path)
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/django/urls/utils.py", line 28, in get_callable
    mod = import_module(mod_name)
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/autoslug/utils.py", line 17, in <module>
    from django.db.models.fields import FieldDoesNotExist, DateField
ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models.fields' (/home/niko/.local/share/virtualenvs/access4all-hL0YrbZN/lib/python3.7/site-packages/django/db/models/fields/__init__.py)

I don't think Django should break imports like that with a large part of the current ecosystem relying on them. Just my opinion though. For now the solution for me is to keep using 3.0.6.

Edit: Woops sorry I thought I was on the Django repository. Will file an issue there. Sorry for the noise.

@n1k0 Did you submit that issue? I am having troubles tracking it in Django's issues. I have the same breaking issue.

having the same issure

@colinschwegmann nope, couldn't figure how to do it on their Track instance. Meanwhile, the culprit package in my case has been updated to fix the issue. I guess now 3.1 stable is released, all other packages relying on importing django.db.models.fields.FieldDoesNotExist will have to issue a fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lucasdavid picture lucasdavid  路  3Comments

ashiksl picture ashiksl  路  3Comments

hackaprende picture hackaprende  路  5Comments

jlhawn picture jlhawn  路  3Comments

bryanveloso picture bryanveloso  路  6Comments