#29617 closed Bug (fixed)
django.template.Template crashes if the template_string argument is lazy
Reported by: | Dražen Odobašić | Owned by: | Dražen Odobašić |
---|---|---|---|
Component: | Template system | 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
- 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 this context lazy objects are usually
- in Django 2.0/master we removed
force_text
so lazy strings are no longer evaluated, and that raises aTypeError: 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
Change History (5)
comment:1 by , 6 years ago
Has patch: | set |
---|---|
Severity: | Normal → Release blocker |
Summary: | Regression - lazy strings are raising TypeError in template Lexer → django.template.Template crashes if the template_string argument is lazy |
Triage Stage: | Unreviewed → Ready for checkin |
Version: | master → 2.0 |
comment:5 by , 4 years ago
It appears that as of this change it is no longer possible to use Template
with bytes since the input is now coerced to str
. 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.
Note:
See TracTickets
for help on using tickets.
PR