﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31099	ValueError: Non-reversible reg-exp portion: '(?i'.	Tom Morse	nobody	"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.
"	Bug	closed	Core (URLs)	3.0	Normal	invalid	case insensitive error admin		Unreviewed	0	0	0	0	0	0
