﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20296	django.utils.safestring.mark_safe forces evaluation of lazy objects	Baptiste Mispelon	Theofilos Alexiou	"Consider the following example:

{{{
#!python
from django.utils.safestring import mark_safe
from django.utils.translation import activate, ugettext_lazy as _

s = mark_safe(_(""username""))
tpl = Template('{{ s }}')
activate('fr')
print(tpl.render(Context({'s': s})))
}}}

I would expect this to output `nom d'utilisateur` (which is the french translation of `username`) but what happens instead is that it outputs `username`.
The reason for this is that `mark_safe` will force the evaluation of the lazy string provided by `ugettext_lazy` when it's called.

Unfortunately, the solution to this it trickier than simply wrapping `mark_safe` with `django.utils.functional.allow_lazy`, because `mark_safe` can operate both on bytes and text (and `allow_lazy` needs to know the type of object return by the wrapped function).

I wrote some tests and a proposed solution on my branch: https://github.com/bmispelon/django/compare/lazy-safedata"	New feature	closed	Utilities	dev	Normal	fixed		bmispelon@…	Ready for checkin	1	0	0	0	0	0
