[Django] #31099: ValueError: Non-reversible reg-exp portion: '(?i'

15 views
Skip to first unread message

Django

unread,
Dec 17, 2019, 6:07:05 PM12/17/19
to django-...@googlegroups.com
#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.

Django

unread,
Dec 18, 2019, 2:45:40 AM12/18/19
to django-...@googlegroups.com
#31099: ValueError: Non-reversible reg-exp portion: '(?i'.
-------------------------------------+-------------------------------------
Reporter: tommorse | Owner: nobody
Type: Bug | Status: closed
Component: Core (URLs) | Version: 3.0
Severity: Normal | Resolution: invalid
Keywords: case insensitive | Triage Stage:
error admin | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* owner: (none) => nobody
* component: Error reporting => Core (URLs)
* resolution: => invalid


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/31099#comment:1>

Reply all
Reply to author
Forward
0 new messages