Skip to content

Commit a77c4e7

Browse files
committed
Add a flag for when the context has been prepared by the config's execution mode already.
This prevents having the meta-context variables get overridden when evaluating an import as it creates a new JinjavaInterpreter based on the current one, which will share the same metaContextVariables set
1 parent b5e4e74 commit a77c4e7

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/main/java/com/hubspot/jinjava/interpret/Context.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public enum Library {
115115
private boolean throwInterpreterErrors = false;
116116
private boolean partialMacroEvaluation = false;
117117
private boolean unwrapRawOverride = false;
118+
private boolean preparedByExecutionMode = false;
118119
private DynamicVariableResolver dynamicVariableResolver = null;
119120
private final Set<String> metaContextVariables; // These variable names aren't tracked in eager execution
120121
private Node currentNode;
@@ -217,6 +218,7 @@ public Context(
217218
this.deferredExecutionMode = parent.deferredExecutionMode;
218219
this.deferLargeObjects = parent.deferLargeObjects;
219220
this.throwInterpreterErrors = parent.throwInterpreterErrors;
221+
this.preparedByExecutionMode = parent.preparedByExecutionMode;
220222
}
221223
}
222224

@@ -825,4 +827,12 @@ public void setCurrentNode(final Node currentNode) {
825827
public boolean isInForLoop() {
826828
return get(ForTag.LOOP) != null;
827829
}
830+
831+
boolean isPreparedByExecutionMode() {
832+
return preparedByExecutionMode;
833+
}
834+
835+
void setPreparedByExecutionMode(boolean preparedByExecutionMode) {
836+
this.preparedByExecutionMode = preparedByExecutionMode;
837+
}
828838
}

src/main/java/com/hubspot/jinjava/interpret/JinjavaInterpreter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ public JinjavaInterpreter(
111111
this.context = context;
112112
this.config = renderConfig;
113113
this.application = application;
114-
115-
this.config.getExecutionMode().prepareContext(this.context);
114+
if (!this.context.isPreparedByExecutionMode()) {
115+
this.config.getExecutionMode().prepareContext(this.context);
116+
this.context.setPreparedByExecutionMode(true);
117+
}
116118

117119
switch (config.getRandomNumberGeneratorStrategy()) {
118120
case THREAD_LOCAL:

0 commit comments

Comments
 (0)