#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:
- django.contrib.admindocs returns HTTP500 for admin/docs/views/
- possibly Django REST Framework SchemaGenerator, when fixing this error by using str(pattern)
Change History (7)
comment:1 by , 7 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 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.
comment:5 by , 7 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
The
__str__
methods of classes defined indjango.urls.resolvers
should be adapted tostr()
the value they are returning.