Opened 4 years ago

Closed 4 years ago

#31099 closed Bug (invalid)

ValueError: Non-reversible reg-exp portion: '(?i'.

Reported by: Tom Morse Owned by: nobody
Component: Core (URLs) Version: 3.0
Severity: Normal Keywords: case insensitive error admin
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The server was reporting these errors when we tried to add Django's Admin module, re_path('^(?i)admin/', admin.site.urls), to our existing urls.py files which contained many re_path()'s with the case insensitive regex (?i). Although the below snippet says version 2.2.7 we got the same errors in Django 3

Django version 2.2.7, using settings 'senselab.settings'
Starting development server at http://127.0.0.1:8200/
Quit the server with CONTROL-C.
Internal Server Error: /admin/
Traceback (most recent call last):
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 241, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 213, in inner
    if request.path == reverse('admin:logout', current_app=self.name):
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/urls/base.py", line 58, in reverse
    app_list = resolver.app_dict[ns]
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 513, in app_dict
    self._populate()
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 453, in _populate
    bits = normalize(url_pattern.pattern.regex.pattern)
  File "/home/tmm46/.local/lib/python3.6/site-packages/django/utils/regex_helper.py", line 126, in normalize
    raise ValueError("Non-reversible reg-exp portion: '(?%s'" % ch)
ValueError: Non-reversible reg-exp portion: '(?i'

The error was fixed when the regex_helper.py file mentioned above had the following change:

<                     if ch in '!=<':
---
>                     if ch in '!=<i':

where the bottom line is the one that fixed our version (the addition of the letter "i"), and the top line is line 120 in todays version in https://github.com/django/django/blob/master/django/utils/regex_helper.py

Although this fix is working for us we wanted to submit it to the community for verification. Sorry we don't have time to condense our code into something that concisely produces the error.

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Component: Error reportingCore (URLs)
Owner: set to nobody
Resolution: invalid
Status: newclosed
Summary: ValueError: Non-reversible reg-exp portion: '(?i'ValueError: Non-reversible reg-exp portion: '(?i'.

Support for inline flags in regular expression groups ((?i), (?L), (?m), (?s), and (?u)) was deprecated in Django 1.11 (see #27648) and removed in Django 2.1.

Note: See TracTickets for help on using tickets.
Back to Top