Opened 7 years ago

Closed 7 years ago

Last modified 7 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 by Simon Charette, 7 years ago

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 by Tilmann Becker, 7 years ago

Owner: changed from nobody to Tilmann Becker
Status: newassigned

comment:3 by Tilmann Becker, 7 years ago

Has patch: set

comment:4 by Simon Charette, 7 years ago

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 7 years ago by Simon Charette (previous) (diff)

comment:5 by Simon Charette, 7 years ago

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

comment:6 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 01384ce:

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

Regression in df41b5a05d4e00e80e73afe629072e37873e767a.

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

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