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

RegexURLResolver no longer exists in Django 2.0(a1) #5456

Closed
5 of 6 tasks
tarkatronic opened this issue Sep 26, 2017 · 6 comments
Closed
5 of 6 tasks

RegexURLResolver no longer exists in Django 2.0(a1) #5456

tarkatronic opened this issue Sep 26, 2017 · 6 comments
Labels
Milestone

Comments

@tarkatronic
Copy link

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

In testing an application against Django 2.0a1, I ran into a confusing error:

  File ".tox/py36-django20/lib/python3.6/site-packages/rest_framework/serializers.py", line 30, in <module>
    from rest_framework.compat import JSONField as ModelJSONField
  File ".tox/py36-django20/lib/python3.6/site-packages/rest_framework/compat.py", line 26, in <module>
    from django.core.urlresolvers import (  # Will be removed in Django 2.0
ModuleNotFoundError: No module named 'django.core.urlresolvers'

After investigating, it is related to a shim for older Django versions which now breaks as of Django 2.0a1:

try:
    from django.urls import (
        NoReverseMatch, RegexURLPattern, RegexURLResolver, ResolverMatch, Resolver404, get_script_prefix, reverse, reverse_lazy, resolve
    )
except ImportError:
    from django.core.urlresolvers import (  # Will be removed in Django 2.0
        NoReverseMatch, RegexURLPattern, RegexURLResolver, ResolverMatch, Resolver404, get_script_prefix, reverse, reverse_lazy, resolve
    )

NoReverseMatch, RegexURLPattern, RegexURLResolver, ResolverMatch, Resolver404, get_script_prefix, reverse, reverse_lazy, resolve

It turns out, RegexURLResolver no longer exists. I would imagine this is related to the new simplified URL patterns.

I'm unsure what the exact fix is at this moment, as I haven't dug into the new url implementation(s) yet, but I do recall that the old regex functionality is being maintained.

@thomwiggers
Copy link

Pretty sure it's URLPattern and URLResolver now. I'm trying to figure this one out.

@thomwiggers
Copy link

thomwiggers commented Oct 2, 2017

Ok, so as far as I've been able to figure out, they're far from drop-in replacements. The entire way resolving paths used to work appears to have been refactored and you would need to do some work to work with this new api. You would need some compatibility shim, as some of the attributes have been renamed or layers of indirection have been added since Django 2.0.

@mastizada
Copy link

Its now django.urls.resolvers.RegexURLPattern

@se-bastiaan
Copy link

django.urls.resolvers.RegexURLPattern doesn't exist anymore either, it was changed in django/django@df41b5a.

@diemuzi
Copy link

diemuzi commented Oct 6, 2017

Also running Django 2.x alpha with the latest Rest Framework

When running python manage.py compress the following output is returned:
https://gist.github.com/diemuzi/e9049c96b703d87d061caa6d018be3fd

Just adding it here in case it helps with any debugging. Would be happy to do anything else to help too.

@anx-ckreuzberger
Copy link
Contributor

I just installed DRF 3.7, and it seems that there still is a compatibility issue with Django 2.0 (a1):

 File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "~/myproject/urls.py", line 4, in <module>
    from django_rest_passwordreset.views import reset_password_request_token, reset_password_confirm
  File "~/myproject/views.py", line 8, in <module>
    from rest_framework import parsers, renderers, status
  File "~/myproject/venv/lib/python3.5/site-packages/rest_framework/parsers.py", line 23, in <module>
    from rest_framework import renderers
  File "~/myproject/venv/lib/python3.5/site-packages/rest_framework/renderers.py", line 24, in <module>
    from rest_framework import VERSION, exceptions, serializers, status
  File "~/myproject/venv/lib/python3.5/site-packages/rest_framework/exceptions.py", line 17, in <module>
    from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList
  File "~/myproject/venv/lib/python3.5/site-packages/rest_framework/utils/serializer_helpers.py", line 8, in <module>
    from rest_framework.compat import unicode_to_repr
  File "~/myproject/venv/lib/python3.5/site-packages/rest_framework/compat.py", line 31, in <module>
    from django.core.urlresolvers import (  # Will be removed in Django 2.0
ImportError: No module named 'django.core.urlresolvers'

Could be fixed by PR #5485

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants