Skip to content

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

Closed

Description

@tarkatronic

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.

Activity

  1. thomwiggers commented on Oct 2, 2017

    @thomwiggers

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

  2. thomwiggers commented on Oct 2, 2017

    @thomwiggers

    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.

  3. mastizada commented on Oct 3, 2017

    @mastizada

    Its now django.urls.resolvers.RegexURLPattern

  4. se-bastiaan commented on Oct 3, 2017

    @se-bastiaan

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

  5. diemuzi commented on Oct 6, 2017

    @diemuzi

    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.

  6. anx-ckreuzberger commented on Oct 9, 2017

    @anx-ckreuzberger
    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

  7. added this to the 3.7.1 Release milestone on Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions