Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#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 Claude Paroz, 4 years ago

comment:2 by Mariusz Felisiak, 4 years ago

Summary: Optional URL params crash some view functionsOptional URL params crash some view functions.
Triage Stage: UnreviewedAccepted

comment:3 by Baptiste Mispelon, 4 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 Mariusz Felisiak, 4 years ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:5 by Mariusz Felisiak, 4 years ago

Has patch: set

comment:6 by Carlton Gibson, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by GitHub <noreply@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 82a88d2f:

Fixed #31061 -- Ignored positional args in django.urls.resolve() when all optional named parameters are missing.

Regression in 76b993a117b61c41584e95149a67d8a1e9f49dd1.

Thanks Claude Paroz for the report and Carlton Gibson for reviews.

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In e986e49e:

[3.0.x] Fixed #31061 -- Ignored positional args in django.urls.resolve() when all optional named parameters are missing.

Regression in 76b993a117b61c41584e95149a67d8a1e9f49dd1.

Thanks Claude Paroz for the report and Carlton Gibson for reviews.
Backport of 82a88d2f48e13ef5d472741d5ed1c183230cfe4c from master

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