#31061 closed Bug (fixed)
Optional URL params crash some view functions.
| Reported by: | Claude Paroz | Owned by: | Mariusz Felisiak |
|---|---|---|---|
| Component: | Core (URLs) | Version: | 3.0 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
My use case, running fine with Django until 2.2:
URLConf:
urlpatterns += [
...
re_path(r'^module/(?P<format>(html|json|xml))?/?$', views.modules, name='modules'),
]
View:
def modules(request, format='html'):
...
return render(...)
With Django 3.0, this is now producing an error:
Traceback (most recent call last):
File "/l10n/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/l10n/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/l10n/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
Exception Type: TypeError at /module/
Exception Value: modules() takes from 1 to 2 positional arguments but 3 were given
Change History (8)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
| Summary: | Optional URL params crash some view functions → Optional URL params crash some view functions. |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 6 years ago
It seems to work if you remove the extra parentheses:
re_path(r'^module/(?P<format>html|json|xml)?/?$', views.modules, name='modules'),
It seems Django is getting confused by the nested groups.
comment:4 by , 6 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:6 by , 6 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Note:
See TracTickets
for help on using tickets.
Tracked regression in 76b993a117b61c41584e95149a67d8a1e9f49dd1.