Opened 22 months ago

Closed 22 months ago

Last modified 22 months 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 Changed 22 months ago by Claude Paroz

comment:2 Changed 22 months ago by Mariusz Felisiak

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

comment:3 Changed 22 months ago by Baptiste Mispelon

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 Changed 22 months ago by Mariusz Felisiak

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:5 Changed 22 months ago by Mariusz Felisiak

Has patch: set

comment:6 Changed 22 months ago by Carlton Gibson

Triage Stage: AcceptedReady for checkin

comment:7 Changed 22 months ago by GitHub <noreply@…>

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 Changed 22 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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