[Django] #29617: Regression - lazy strings are raising TypeError in template Lexer

10 views
Skip to first unread message

Django

unread,
Jul 31, 2018, 5:13:12 AM7/31/18
to django-...@googlegroups.com
#29617: Regression - lazy strings are raising TypeError in template Lexer
-------------------------------------+-------------------------------------
Reporter: Dražen | Owner: Dražen Odobašić
Odobašić |
Type: Bug | Status: assigned
Component: Template | Version: master
system |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
* in Django 1.11 we were using `force_text` when initializing templates
and that evaluated any lazy objects -
https://github.com/django/django/commit/3a148f958dddd97c1379081118c30fbede6b6bc4
#diff-8cbe1fb6d589cb6e35b956704d7a1285L154
* in this context lazy objects are usually `gettext` wrapped strings

* in Django 2.0/master we removed `force_text` so lazy strings are no
longer evaluated, and that raises a `TypeError: expected string or bytes-
like object` -
https://github.com/django/django/blob/2.0.7/django/template/base.py#L349

* proposed solution: use `str` to force evaluation of lazy objects

--
Ticket URL: <https://code.djangoproject.com/ticket/29617>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 31, 2018, 8:58:49 AM7/31/18
to django-...@googlegroups.com
#29617: django.template.Template crashes if the template_string argument is lazy
-------------------------------------+-------------------------------------
Reporter: Dražen Odobašić | Owner: Dražen

| Odobašić
Type: Bug | Status: assigned
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1
* severity: Normal => Release blocker
* version: master => 2.0
* stage: Unreviewed => Ready for checkin


Comment:

[https://github.com/django/django/pull/10247 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29617#comment:1>

Django

unread,
Jul 31, 2018, 9:57:37 AM7/31/18
to django-...@googlegroups.com
#29617: django.template.Template crashes if the template_string argument is lazy
-------------------------------------+-------------------------------------
Reporter: Dražen Odobašić | Owner: Dražen
| Odobašić
Type: Bug | Status: closed

Component: Template system | Version: 2.0
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"9f3b9ffd51c71d96728df9ee16f5a57c6f3b315d" 9f3b9ff]:
{{{
#!CommitTicketReference repository=""
revision="9f3b9ffd51c71d96728df9ee16f5a57c6f3b315d"
Fixed #29617 -- Fixed Template crash if template_string is lazy.

Regression in 3a148f958dddd97c1379081118c30fbede6b6bc4.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29617#comment:2>

Django

unread,
Jul 31, 2018, 10:03:50 AM7/31/18
to django-...@googlegroups.com
#29617: django.template.Template crashes if the template_string argument is lazy
-------------------------------------+-------------------------------------
Reporter: Dražen Odobašić | Owner: Dražen
| Odobašić
Type: Bug | Status: closed
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"4dadf4eb7bad7c8e9154ff86e7e42ed846c8974d" 4dadf4e]:
{{{
#!CommitTicketReference repository=""
revision="4dadf4eb7bad7c8e9154ff86e7e42ed846c8974d"
[2.1.x] Fixed #29617 -- Fixed Template crash if template_string is lazy.

Regression in 3a148f958dddd97c1379081118c30fbede6b6bc4.
Backport of 9f3b9ffd51c71d96728df9ee16f5a57c6f3b315d from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29617#comment:3>

Django

unread,
Jul 31, 2018, 10:13:16 AM7/31/18
to django-...@googlegroups.com
#29617: django.template.Template crashes if the template_string argument is lazy
-------------------------------------+-------------------------------------
Reporter: Dražen Odobašić | Owner: Dražen
| Odobašić
Type: Bug | Status: closed
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"253f1b74daac6300f6670929bfc0540ce1e71f7a" 253f1b74]:
{{{
#!CommitTicketReference repository=""
revision="253f1b74daac6300f6670929bfc0540ce1e71f7a"
[2.0.x] Fixed #29617 -- Fixed Template crash if template_string is lazy.

Regression in 3a148f958dddd97c1379081118c30fbede6b6bc4.
Backport of 9f3b9ffd51c71d96728df9ee16f5a57c6f3b315d from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29617#comment:4>

Django

unread,
Jun 24, 2020, 12:39:28 PM6/24/20
to django-...@googlegroups.com
#29617: django.template.Template crashes if the template_string argument is lazy
-------------------------------------+-------------------------------------
Reporter: Dražen Odobašić | Owner: Dražen
| Odobašić
Type: Bug | Status: closed
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Daniel Miller):

It appears that as of
[https://github.com/django/django/commit/4dadf4eb7bad7c8e9154ff86e7e42ed846c8974d
this change] it is no longer possible to use `Template` with bytes since
the input is now coerced to `str`. [https://github.com/dimagi/commcare-
hq/pull/27911/commits/897b3ff56cdef6179f1d4373f34b15d9d5411fec CommCareHQ
was using that feature] and ran into the issue while upgrading Django. I
did not see mention of this backward-incompatible change in the release
notes.

--
Ticket URL: <https://code.djangoproject.com/ticket/29617#comment:5>

Reply all
Reply to author
Forward
0 new messages