Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#28947 closed Bug (fixed)

str(path) causes TypeError when using translatable URL patterns

Reported by: Tilmann Becker Owned by: Tilmann Becker
Component: Core (URLs) Version: 2.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

Using translatable URL patterns like this

from django.utils.translation import gettext_lazy as _

p = path(_('example/'), ExampleView.as_view())
print(p)

# or

p = re_path(_(r'^example/$'), ExampleView.as_view())
print(p)

causes

TypeError: __str__ returned non-string (type __proxy__)

It should print a string representation of the URL pattern instead:

<URLPattern 'example/''>

This affects some consumers of URL patterns:

Change History (7)

comment:1 Changed 3 years ago by Simon Charette

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

The __str__ methods of classes defined in django.urls.resolvers should be adapted to str() the value they are returning.

comment:2 Changed 3 years ago by Tilmann Becker

Owner: changed from nobody to Tilmann Becker
Status: newassigned

comment:3 Changed 3 years ago by Tilmann Becker

Has patch: set

comment:4 Changed 3 years ago by Simon Charette

Needs tests: set
Patch needs improvement: set

Patch still needs tests and release notes for 2.0.1 as it's meant to be backported.

Last edited 3 years ago by Simon Charette (previous) (diff)

comment:5 Changed 3 years ago by Simon Charette

Needs tests: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:6 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 01384ce:

Fixed #28947 -- Fixed crash when coercing a translatable URL pattern to str.

Regression in df41b5a05d4e00e80e73afe629072e37873e767a.

comment:7 Changed 3 years ago by Tim Graham <timograham@…>

In c99ab335:

[2.0.x] Fixed #28947 -- Fixed crash when coercing a translatable URL pattern to str.

Regression in df41b5a05d4e00e80e73afe629072e37873e767a.

Backport of 01384ce36c3fddfbcc5af6e1108bdb8cd3e9389d from master

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