Skip to content

Commit

Permalink
fix: Always reset globals on cached templates (frappe#30897)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush authored Jan 28, 2025
1 parent baf884d commit 32c1220
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions frappe/utils/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def is_safe_attribute(self, obj, attr, *args, **kwargs):

return super().is_safe_attribute(obj, attr, *args, **kwargs)

def get_template(self, *args, **kwargs):
# Note: jenv globals are reapplied here because we don't have true "global"/"local" separation.
# Ideally globals should never change as per Jinja design.
kwargs.update({"globals": self.globals})
return super().get_template(*args, **kwargs)

# frappe will be loaded last, so app templates will get precedence
jenv = FrappeSandboxedEnvironment(loader=get_jloader(), undefined=DebugUndefined, cache_size=32)
set_filters(jenv)
Expand All @@ -61,9 +67,7 @@ def is_safe_attribute(self, obj, attr, *args, **kwargs):

def get_template(path):
jenv = get_jenv()
# Note: jenv globals are reapplied here because we don't have true "global"/"local" separation.
# Ideally globals should never change as per Jinja design.
return jenv.get_template(path, globals=jenv.globals)
return jenv.get_template(path)


def get_email_from_template(name, args):
Expand Down

0 comments on commit 32c1220

Please sign in to comment.