diff --git a/src/main/java/com/hubspot/jinjava/interpret/Context.java b/src/main/java/com/hubspot/jinjava/interpret/Context.java index 22e938199..5bea6d73b 100644 --- a/src/main/java/com/hubspot/jinjava/interpret/Context.java +++ b/src/main/java/com/hubspot/jinjava/interpret/Context.java @@ -115,6 +115,7 @@ public enum Library { private boolean throwInterpreterErrors = false; private boolean partialMacroEvaluation = false; private boolean unwrapRawOverride = false; + private boolean preparedByExecutionMode = false; private DynamicVariableResolver dynamicVariableResolver = null; private final Set metaContextVariables; // These variable names aren't tracked in eager execution private Node currentNode; @@ -217,6 +218,7 @@ public Context( this.deferredExecutionMode = parent.deferredExecutionMode; this.deferLargeObjects = parent.deferLargeObjects; this.throwInterpreterErrors = parent.throwInterpreterErrors; + this.preparedByExecutionMode = parent.preparedByExecutionMode; } } @@ -825,4 +827,12 @@ public void setCurrentNode(final Node currentNode) { public boolean isInForLoop() { return get(ForTag.LOOP) != null; } + + boolean isPreparedByExecutionMode() { + return preparedByExecutionMode; + } + + void setPreparedByExecutionMode(boolean preparedByExecutionMode) { + this.preparedByExecutionMode = preparedByExecutionMode; + } } diff --git a/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java b/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java index dc7bee8f4..d5446b412 100644 --- a/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java +++ b/src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java @@ -111,8 +111,10 @@ public JinjavaInterpreter( this.context = context; this.config = renderConfig; this.application = application; - - this.config.getExecutionMode().prepareContext(this.context); + if (!this.context.isPreparedByExecutionMode()) { + this.config.getExecutionMode().prepareContext(this.context); + this.context.setPreparedByExecutionMode(true); + } switch (config.getRandomNumberGeneratorStrategy()) { case THREAD_LOCAL: