Regression? evaluation of a lazy string in Template

52 views
Skip to first unread message

Dražen Odobašić

unread,
Jul 30, 2018, 4:59:51 AM7/30/18
to django-d...@googlegroups.com
Hi,

we are using Template engine to convert some translatable textual class level
attributes, like [0]. In the process of migration to Django2.0, we got a problem
with template Lexer which raises a `TypeError: expected string or bytes-like
object` [1]

I'm not sure if are just misusing the template system to do something what it
wasn't designed for, or if this is a regression from Django 1.11. Previously
Django was using `force_text` to force evaluation of a lazy string [2] and Lexer
always got a text object.

We could force the evaluation of the lazy strings in the application, but I was
wandering if this is a regression, and should actually be fixed in Django?

Dražen


[0]
https://github.com/rapidpro/rapidpro/blob/master/temba/channels/types/telegram/type.py#L27
[1] https://github.com/django/django/blob/2.0.7/django/template/base.py#L349
[2]
https://github.com/django/django/commit/3a148f958dddd97c1379081118c30fbede6b6bc4#diff-8cbe1fb6d589cb6e35b956704d7a1285L154

Tim Graham

unread,
Jul 30, 2018, 9:19:22 AM7/30/18
to Django developers (Contributions to Django itself)
It doesn't look like that force_text() was added specifically to handle lazy strings (see django/template/__init__.py in https://github.com/django/django/commit/953badbea5a04159adbfa970f5805c0232b6a401) but Django does have str() calls in various places to handle lazy strings, e.g. https://github.com/django/django/blob/cebbcaa1baa6eb7f9ec3e223abdc496a983ea482/django/urls/resolvers.py#L486. I think it would be fine to restore the old behavior. Can you create a ticket and offer a patch before the final bug fix release for Django 2.0.x on Wednesday?

Dražen Odobašić

unread,
Jul 30, 2018, 10:13:48 AM7/30/18
to django-d...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages