#31099: ValueError: Non-reversible reg-exp portion: '(?i'
-------------------------------------+-------------------------------------
               Reporter:  tommorse   |          Owner:  (none)
                   Type:  Bug        |         Status:  new
              Component:  Error      |        Version:  3.0
  reporting                          |       Keywords:  case insensitive
               Severity:  Normal     |  error admin
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31099>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.b2c324d3455ba3f5fadace059c37e328%40djangoproject.com.

Reply via email to