Drf-yasg: Incompatibility with latest DRF 3.12.0

Created on 28 Sep 2020  路  23Comments  路  Source: axnsan12/drf-yasg

Encode has just released the new version of DRF django-rest-framework 3.12.0 which has dropped all compat support to Django < 2 urls

Affected import in dry-yasg

from rest_framework.compat import URLPattern, URLResolver, get_original_route

DRF merged PR
DRF Commit

Most helpful comment

@axnsan12, could we get your attention here?
Also, the build is failing because of unrelated issues, should we raise an issue to resolve it?

All 23 comments

Hi,
Here in compat.py file there are removed lines highlighted: https://github.com/encode/django-rest-framework/compare/3.11.1...3.12.0

I also noticed this problem about 1 hour ago as 3.12.0 DRF was released. Currently I had to use fixed requirement of DRF 3.11.1

Let me add some logs to make better search engine inexing ;)

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run
    self.check(display_num_errors=True)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check
    all_issues = checks.run_checks(
  File "/usr/local/lib/python3.8/site-packages/django/core/checks/registry.py", line 70, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 408, in check
    for pattern in self.url_patterns:
  File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 589, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/app/main/urls.py", line 36, in <module>
    SchemaView = get_schema_view(
  File "/usr/local/lib/python3.8/site-packages/drf_yasg/views.py", line 67, in get_schema_view
    _generator_class = generator_class or swagger_settings.DEFAULT_GENERATOR_CLASS
  File "/usr/local/lib/python3.8/site-packages/drf_yasg/app_settings.py", line 122, in __getattr__
    val = perform_import(val, attr)
  File "/usr/local/lib/python3.8/site-packages/rest_framework/settings.py", line 166, in perform_import
    return import_from_string(val, setting_name)
  File "/usr/local/lib/python3.8/site-packages/rest_framework/settings.py", line 180, in import_from_string
    raise ImportError(msg)
ImportError: Could not import 'drf_yasg.generators.OpenAPISchemaGenerator' for API setting 'DEFAULT_GENERATOR_CLASS'. ImportError: cannot import name 'URLPattern' from 'rest_framework.compat' (/usr/local/lib/python3.8/site-packages/rest_framework/compat.py).

Patched with #642

I think we should also drop support of Django < 2.1
Raised PR #644

@axnsan12, could we get your attention here?
Also, the build is failing because of unrelated issues, should we raise an issue to resolve it?

Having same issue here after updating to 3.12.1, (running with django 3.1.2 on Ubuntu).

Traceback (most recent call last):
  File "manage.py", line 31, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.8/site-packages/django_extensions/management/commands/shell_plus.py", line 120, in run_from_argv
    return super().run_from_argv(argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 368, in execute
    self.check()
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check
    all_issues = checks.run_checks(
  File "/usr/local/lib/python3.8/site-packages/django/core/checks/registry.py", line 70, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 408, in check
    for pattern in self.url_patterns:
  File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 589, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/config/urls.py", line 21, in <module>
    schema_view = get_schema_view(
  File "/usr/local/lib/python3.8/site-packages/drf_yasg/views.py", line 67, in get_schema_view
    _generator_class = generator_class or swagger_settings.DEFAULT_GENERATOR_CLASS
  File "/usr/local/lib/python3.8/site-packages/drf_yasg/app_settings.py", line 122, in __getattr__
    val = perform_import(val, attr)
  File "/usr/local/lib/python3.8/site-packages/rest_framework/settings.py", line 166, in perform_import
    return import_from_string(val, setting_name)
  File "/usr/local/lib/python3.8/site-packages/rest_framework/settings.py", line 180, in import_from_string
    raise ImportError(msg)
ImportError: Could not import 'drf_yasg.generators.OpenAPISchemaGenerator' for API setting 'DEFAULT_GENERATOR_CLASS'. ImportError: cannot import name 'URLPattern' from 'rest_framework.compat' (/usr/local/lib/python3.8/site-packages/rest_framework/compat.py).

same here @OmenApps

same problem than @OmenApps

same problem than @OmenApps

do update on drf, for me decided

I'm worried this project is no longer maintained given that there has been no activity since February (#590).

The maintainer, @axnsan12, is still slightly active on GitHub (see https://github.com/rabbitmq/rabbitmq-management/issues/836#issue-678646238 dated Aug 13), but there hasn't been any activity on this repo.

Does the project need to be forked?

I'm worried this project is no longer maintained given that there has been no activity since February (#590).

The maintainer, @axnsan12, is still slightly active on GitHub (see rabbitmq/rabbitmq-management#836 (comment) dated Aug 13), but there hasn't been any activity on this repo.

Does the project need to be forked?

We can continue on my fork, drf-yasg2. Would someone like to volunteer to fix the test suite and build failures?

Thanks!

Here are some PR's I triaged that would be good to migrate over:

Typos:

Perhaps we should comment on the PRs when they've been merged into the fork so that if people need the fix, they know to check out drf-yasq2.

@JoelLefkowitz I see your repo doesn't have the issue tracker enabled. Should it be so that issues can be tracked against the fork moving forward?

@johnthagen Issues now enabled

Hi.
Is it any chance you are gonna release a patched version on this issue?
Thanks and thanks for the package, its awesome!

Same problem here. Sad to see this package dying...

Same problem here. Sad to see this package dying...

Since the maintainers of this repo are not replying, we've moved to my fork drf-yasg2

I wrote an email to the owner of this repository stating the problems, I hope he has a solution.

Please note a compatible and stable version of this package is now available on pypi; drf-yasg2

Uninstalling drf-yasg & then installing drf_yasg2 fixed this for me

Probably means I should move some of my patches over to drf_yasg2.

Since the maintainers of this repo are not replying, we've moved to my fork drf-yasg2

@JoelLefkowitz I was thinking to update the description of the issue, to move to drf-yasg2
and close the same. What you say?

Even I have been already moved to drf-yasg2. Thanks to you

I was thinking to update the description of the issue, to move to drf-yasg2 and close the same.

@fasih I went ahead and created a new issue with a clear title about the fork. I think it's good to keep this issue open to document the clear DRF 3.12 problem for current users of drf-yasg to reference.

1.20.0 is now out with the fix. I think we can consider this closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iamhssingh picture iamhssingh  路  3Comments

maikotz picture maikotz  路  4Comments

mkurnikov picture mkurnikov  路  3Comments

nicholasgcoles picture nicholasgcoles  路  4Comments

marcosgeorgopoulos picture marcosgeorgopoulos  路  4Comments