File tree Expand file tree Collapse file tree
transifex/native/django/templatetags Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -224,13 +224,22 @@ def render(self, context):
224224 source_icu_template , locale ,
225225 escape = False )
226226
227+ # `self` is not supposed to mutate between invocations of `render`
228+ # because Django may parse the template once per thread and reuse the
229+ # nodes between renders ("parse" = "process text into nodes"). To that
230+ # end, let's safekeep the old value of `self.source_string.var` to put
231+ # it back in place before returning from render.
232+ # https://docs.djangoproject.com/en/1.11/howto/custom-template-tags/#thread-safety-considerations # noqa
233+ old_source_string_var = self .source_string .var
234+
227235 # Now we resolve the full source filter expression, after having
228236 # replaced its text with the outcome of the translation, in order to
229237 # apply the expression's filters to the translation. The translation is
230238 # marked as safe in order to prevent further escaping attempts that
231239 # would introduce the danger of double escaping (eg `<` => `&lt;`)
232240 self .source_string .var = mark_safe (result )
233241 result = self .source_string .resolve (context )
242+ self .source_string .var = old_source_string_var
234243
235244 if self .asvar is not None :
236245 # Save the translation outcome to a context variable
You can’t perform that action at this time.
0 commit comments